-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write directly to output stream in OtlpHttpTraceExportClient. (#2490)
- Loading branch information
1 parent
f8f2018
commit d119447
Showing
4 changed files
with
151 additions
and
11 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
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
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,104 @@ | ||
// <copyright file="OtlpHttpExporterBenchmarks.cs" company="OpenTelemetry Authors"> | ||
// 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. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using BenchmarkDotNet.Attributes; | ||
using Benchmarks.Helper; | ||
using OpenTelemetry; | ||
using OpenTelemetry.Exporter; | ||
using OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient; | ||
using OpenTelemetry.Internal; | ||
using OpenTelemetry.Tests; | ||
|
||
namespace Benchmarks.Exporter | ||
{ | ||
[MemoryDiagnoser] | ||
public class OtlpHttpExporterBenchmarks | ||
{ | ||
private readonly byte[] buffer = new byte[1024 * 1024]; | ||
private IDisposable server; | ||
private string serverHost; | ||
private int serverPort; | ||
private OtlpTraceExporter exporter; | ||
private Activity activity; | ||
private CircularBuffer<Activity> activityBatch; | ||
|
||
[Params(1, 10, 100)] | ||
public int NumberOfBatches { get; set; } | ||
|
||
[Params(10000)] | ||
public int NumberOfSpans { get; set; } | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
this.server = TestHttpServer.RunServer( | ||
(ctx) => | ||
{ | ||
using (Stream receiveStream = ctx.Request.InputStream) | ||
{ | ||
while (true) | ||
{ | ||
if (receiveStream.Read(this.buffer, 0, this.buffer.Length) == 0) | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
|
||
ctx.Response.StatusCode = 200; | ||
ctx.Response.OutputStream.Close(); | ||
}, | ||
out this.serverHost, | ||
out this.serverPort); | ||
|
||
var options = new OtlpExporterOptions | ||
{ | ||
Endpoint = new Uri($"http://{this.serverHost}:{this.serverPort}"), | ||
}; | ||
this.exporter = new OtlpTraceExporter( | ||
options, | ||
new OtlpHttpTraceExportClient(options)); | ||
|
||
this.activity = ActivityHelper.CreateTestActivity(); | ||
this.activityBatch = new CircularBuffer<Activity>(this.NumberOfSpans); | ||
} | ||
|
||
[GlobalCleanup] | ||
public void GlobalCleanup() | ||
{ | ||
this.exporter.Shutdown(); | ||
this.exporter.Dispose(); | ||
this.server.Dispose(); | ||
} | ||
|
||
[Benchmark] | ||
public void OtlpExporter_Batching() | ||
{ | ||
for (int i = 0; i < this.NumberOfBatches; i++) | ||
{ | ||
for (int c = 0; c < this.NumberOfSpans; c++) | ||
{ | ||
this.activityBatch.Add(this.activity); | ||
} | ||
|
||
this.exporter.Export(new Batch<Activity>(this.activityBatch, this.NumberOfSpans)); | ||
} | ||
} | ||
} | ||
} |
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