-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ExportSpans benchmark to Jaeger exporter (#1805)
- Loading branch information
Showing
1 changed file
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package jaeger | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"go.opentelemetry.io/otel/sdk/instrumentation" | ||
tracesdk "go.opentelemetry.io/otel/sdk/trace" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
var ( | ||
traceID trace.TraceID | ||
spanID trace.SpanID | ||
spanContext trace.SpanContext | ||
|
||
instrLibName = "benchmark.tests" | ||
) | ||
|
||
func init() { | ||
var err error | ||
traceID, err = trace.TraceIDFromHex("0102030405060708090a0b0c0d0e0f10") | ||
if err != nil { | ||
panic(err) | ||
} | ||
spanID, err = trace.SpanIDFromHex("0102030405060708") | ||
if err != nil { | ||
panic(err) | ||
} | ||
spanContext = trace.NewSpanContext(trace.SpanContextConfig{ | ||
TraceID: traceID, | ||
SpanID: spanID, | ||
}) | ||
} | ||
|
||
func spans(n int) []*tracesdk.SpanSnapshot { | ||
now := time.Now() | ||
s := make([]*tracesdk.SpanSnapshot, n) | ||
for i := 0; i < n; i++ { | ||
name := fmt.Sprintf("span %d", i) | ||
s[i] = &tracesdk.SpanSnapshot{ | ||
SpanContext: spanContext, | ||
Name: name, | ||
StartTime: now, | ||
EndTime: now, | ||
SpanKind: trace.SpanKindClient, | ||
InstrumentationLibrary: instrumentation.Library{ | ||
Name: instrLibName, | ||
}, | ||
} | ||
} | ||
return s | ||
} | ||
|
||
func benchmarkExportSpans(b *testing.B, o EndpointOption, i int) { | ||
ctx := context.Background() | ||
s := spans(i) | ||
exp, err := NewRawExporter(o, WithBatchMaxCount(i+1), WithBufferMaxCount(i+1)) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
|
||
b.ReportAllocs() | ||
b.ResetTimer() | ||
|
||
for n := 0; n < b.N; n++ { | ||
if err := exp.ExportSpans(ctx, s); err != nil { | ||
b.Error(err) | ||
} | ||
exp.bundler.Flush() | ||
} | ||
} | ||
|
||
func benchmarkCollector(b *testing.B, i int) { | ||
benchmarkExportSpans(b, withTestCollectorEndpoint(), i) | ||
} | ||
|
||
func benchmarkAgent(b *testing.B, i int) { | ||
benchmarkExportSpans(b, WithAgentEndpoint(), i) | ||
} | ||
|
||
func BenchmarkCollectorExportSpans1(b *testing.B) { benchmarkCollector(b, 1) } | ||
func BenchmarkCollectorExportSpans10(b *testing.B) { benchmarkCollector(b, 10) } | ||
func BenchmarkCollectorExportSpans100(b *testing.B) { benchmarkCollector(b, 100) } | ||
func BenchmarkCollectorExportSpans1000(b *testing.B) { benchmarkCollector(b, 1000) } | ||
func BenchmarkCollectorExportSpans10000(b *testing.B) { benchmarkCollector(b, 10000) } | ||
func BenchmarkAgentExportSpans1(b *testing.B) { benchmarkAgent(b, 1) } | ||
func BenchmarkAgentExportSpans10(b *testing.B) { benchmarkAgent(b, 10) } | ||
func BenchmarkAgentExportSpans100(b *testing.B) { benchmarkAgent(b, 100) } | ||
|
||
/* | ||
* BUG: These tests are not possible currently because the thrift payload size | ||
* does not fit in a UDP packet with the default size (65000) and will return | ||
* an error. | ||
func BenchmarkAgentExportSpans1000(b *testing.B) { benchmarkAgent(b, 1000) } | ||
func BenchmarkAgentExportSpans10000(b *testing.B) { benchmarkAgent(b, 10000) } | ||
*/ |