Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add otlp log and trace exporter benchmarks #4807

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f38a31a
add benchmarks
vishweshbankwar Aug 21, 2023
25bf0e3
format
vishweshbankwar Aug 21, 2023
400117c
file header
vishweshbankwar Aug 21, 2023
2171b1c
file header
vishweshbankwar Aug 21, 2023
cfb79bf
update benchmark
vishweshbankwar Aug 22, 2023
50c422d
update
vishweshbankwar Aug 28, 2023
5869760
whitespace
vishweshbankwar Aug 28, 2023
ea6df24
Merge branch 'main' into vibankwa/add-benchmark-log-otlp
vishweshbankwar Aug 28, 2023
fb0b468
trailing space
vishweshbankwar Aug 28, 2023
01699b3
Merge branch 'vibankwa/add-benchmark-log-otlp' of https://github.com/…
vishweshbankwar Aug 28, 2023
38edff1
fix format
vishweshbankwar Aug 28, 2023
46ae906
sanity
vishweshbankwar Aug 28, 2023
130574e
fix build
vishweshbankwar Aug 28, 2023
47f6e47
fix
vishweshbankwar Aug 28, 2023
4dd61a4
add trace benchmark
vishweshbankwar Aug 28, 2023
4cfbc43
Merge branch 'main' into vibankwa/add-benchmark-log-otlp
vishweshbankwar Aug 28, 2023
2f8e050
fix grpc benchmarks
vishweshbankwar Aug 29, 2023
2c11581
Merge branch 'vibankwa/add-benchmark-log-otlp' of https://github.com/…
vishweshbankwar Aug 29, 2023
cbdbb57
rmv unused code
vishweshbankwar Aug 29, 2023
2934edd
revert
vishweshbankwar Aug 29, 2023
4a47f09
fix check
vishweshbankwar Aug 29, 2023
e100078
format
vishweshbankwar Aug 29, 2023
7350a01
Merge branch 'main' into vibankwa/add-benchmark-log-otlp
vishweshbankwar Aug 29, 2023
019515d
format
vishweshbankwar Aug 29, 2023
c92d080
Update test/Benchmarks/Exporter/OtlpLogExporterBenchmarks.cs
vishweshbankwar Aug 29, 2023
5f6cbe4
Update test/Benchmarks/Exporter/OtlpTraceExporterBenchmarks.cs
vishweshbankwar Aug 29, 2023
8a270bd
pr feedback
vishweshbankwar Aug 29, 2023
a58b2dc
Merge branch 'vibankwa/add-benchmark-log-otlp' of https://github.com/…
vishweshbankwar Aug 29, 2023
d30c8f9
refactor
vishweshbankwar Aug 29, 2023
f5ad1cb
remove using
vishweshbankwar Aug 29, 2023
703fc8f
Merge branch 'main' into vibankwa/add-benchmark-log-otlp
utpilla Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions test/Benchmarks/Exporter/OtlpLogExporterBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// <copyright file="OtlpLogExporterBenchmarks.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>

extern alias OpenTelemetryProtocol;

using BenchmarkDotNet.Attributes;
using Benchmarks.Helper;
using Grpc.Core;
using Moq;
using OpenTelemetry;
using OpenTelemetry.Internal;
using OpenTelemetry.Logs;
using OpenTelemetry.Tests;
using OpenTelemetryProtocol::OpenTelemetry.Exporter;
using OpenTelemetryProtocol::OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation;
using OpenTelemetryProtocol::OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation.ExportClient;
using OtlpCollector = OpenTelemetryProtocol::OpenTelemetry.Proto.Collector.Logs.V1;

namespace Benchmarks.Exporter;

/*
BenchmarkDotNet v0.13.6, Windows 11 (10.0.22621.2134/22H2/2022Update/SunValley2) (Hyper-V)
AMD EPYC 7763, 1 CPU, 16 logical and 8 physical cores
.NET SDK 7.0.400
[Host] : .NET 7.0.10 (7.0.1023.36312), X64 RyuJIT AVX2
DefaultJob : .NET 7.0.10 (7.0.1023.36312), X64 RyuJIT AVX2


| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
|------------------ |-----------:|----------:|----------:|-------:|-------:|----------:|
| OtlpExporter_Http | 147.112 us | 2.9354 us | 2.4512 us | 0.7324 | 0.4883 | 12289 B |
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved
| OtlpExporter_Grpc | 2.071 us | 0.0410 us | 0.0456 us | 0.0572 | 0.0534 | 968 B |
*/

public class OtlpLogExporterBenchmarks
{
private readonly byte[] buffer = new byte[1024 * 1024];
private OtlpLogExporter exporter;
private LogRecord logRecord;
private CircularBuffer<LogRecord> logRecordBatch;

private IDisposable server;
private string serverHost;
private int serverPort;

[GlobalSetup(Target = nameof(OtlpExporter_Grpc))]
public void GlobalSetupGrpc()
{
var mockClient = new Mock<OtlpCollector.LogsService.LogsServiceClient>();
mockClient
.Setup(m => m.Export(
It.IsAny<OtlpCollector.ExportLogsServiceRequest>(),
It.IsAny<Metadata>(),
It.IsAny<DateTime?>(),
It.IsAny<CancellationToken>()))
.Returns(new OtlpCollector.ExportLogsServiceResponse());

var options = new OtlpExporterOptions();
this.exporter = new OtlpLogExporter(
options,
new SdkLimitOptions(),
new OtlpGrpcLogExportClient(options, mockClient.Object));

this.logRecord = LogRecordHelper.CreateTestLogRecord();
this.logRecordBatch = new CircularBuffer<LogRecord>(1);
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved
}

[GlobalSetup(Target = nameof(OtlpExporter_Http))]
public void GlobalSetupHttp()
{
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 OtlpLogExporter(
vishweshbankwar marked this conversation as resolved.
Show resolved Hide resolved
options,
new SdkLimitOptions(),
new OtlpHttpLogExportClient(options, options.HttpClientFactory()));

this.logRecord = LogRecordHelper.CreateTestLogRecord();
this.logRecordBatch = new CircularBuffer<LogRecord>(1);
this.logRecordBatch.Add(this.logRecord);
}

[GlobalCleanup(Target = nameof(OtlpExporter_Grpc))]
public void GlobalCleanupGrpc()
{
this.exporter.Shutdown();
this.exporter.Dispose();
}

[GlobalCleanup(Target = nameof(OtlpExporter_Http))]
public void GlobalCleanupHttp()
{
this.exporter.Shutdown();
this.exporter.Dispose();
this.server.Dispose();
}

[Benchmark]
public void OtlpExporter_Http()
{
this.exporter.Export(new Batch<LogRecord>(this.logRecordBatch, 1));
}

[Benchmark]
public void OtlpExporter_Grpc()
{
this.exporter.Export(new Batch<LogRecord>(this.logRecordBatch, 1));
}
}
37 changes: 37 additions & 0 deletions test/Benchmarks/Helper/LogRecordHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// <copyright file="LogRecordHelper.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 Microsoft.Extensions.Logging;
using OpenTelemetry.Logs;

namespace Benchmarks.Helper;

internal class LogRecordHelper
{
internal static LogRecord CreateTestLogRecord()
{
var items = new List<LogRecord>(1);
using var factory = LoggerFactory.Create(builder => builder
.AddOpenTelemetry(loggerOptions =>
{
loggerOptions.AddInMemoryExporter(items);
}));

var logger = factory.CreateLogger("TestLogger");
logger.LogInformation("Hello from {Food} {Price}.", "artichoke", 3.99);
return items[0];
}
}