Skip to content

Commit

Permalink
[benchmarks] Add LogBenchmark when BatchProcessor is used (#5746)
Browse files Browse the repository at this point in the history
Co-authored-by: Piotr Kiełkowicz <pkiekowicz@splunk.com>
Co-authored-by: Reiley Yang <reyang@microsoft.com>
  • Loading branch information
3 people authored Jul 16, 2024
1 parent dbe2ce3 commit ccd3759
Showing 1 changed file with 47 additions and 23 deletions.
70 changes: 47 additions & 23 deletions test/Benchmarks/Logs/LogBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@
using OpenTelemetry.Logs;

/*
BenchmarkDotNet v0.13.10, Windows 11 (10.0.22621.3007/22H2/2022Update/SunValley2)
BenchmarkDotNet v0.13.10, Windows 11 (10.0.22631.3880/23H2/2023Update/SunValley3)
11th Gen Intel Core i7-1185G7 3.00GHz, 1 CPU, 8 logical and 4 physical cores
.NET SDK 8.0.101
[Host] : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|------------------------------ |-----------:|----------:|----------:|-------:|----------:|
| NoListenerStringInterpolation | 124.458 ns | 2.5188 ns | 2.2329 ns | 0.0114 | 72 B |
| NoListenerExtensionMethod | 36.326 ns | 0.2916 ns | 0.2435 ns | 0.0102 | 64 B |
| NoListener | 1.375 ns | 0.0586 ns | 0.0896 ns | - | - |
| UnnecessaryIsEnabledCheck | 1.332 ns | 0.0225 ns | 0.0188 ns | - | - |
| CreateLoggerRepeatedly | 48.295 ns | 0.5951 ns | 0.4970 ns | 0.0038 | 24 B |
| OneProcessor | 98.133 ns | 1.8805 ns | 1.5703 ns | 0.0063 | 40 B |
| TwoProcessors | 105.414 ns | 0.4610 ns | 0.3850 ns | 0.0063 | 40 B |
| ThreeProcessors | 102.023 ns | 1.4187 ns | 1.1847 ns | 0.0063 | 40 B |
.NET SDK 8.0.107
[Host] : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX2
| Method | Mean | Error | StdDev | Median | Gen0 | Gen1 | Allocated |
|------------------------------ |-----------:|----------:|-----------:|-----------:|-------:|-------:|----------:|
| NoListenerStringInterpolation | 135.503 ns | 2.7458 ns | 4.5114 ns | 135.391 ns | 0.0114 | - | 72 B |
| NoListenerExtensionMethod | 40.218 ns | 0.8249 ns | 2.2581 ns | 39.809 ns | 0.0102 | - | 64 B |
| NoListener | 1.930 ns | 0.0626 ns | 0.1264 ns | 1.889 ns | - | - | - |
| UnnecessaryIsEnabledCheck | 1.531 ns | 0.0542 ns | 0.1267 ns | 1.518 ns | - | - | - |
| CreateLoggerRepeatedly | 53.797 ns | 1.0927 ns | 1.7331 ns | 53.401 ns | 0.0038 | - | 24 B |
| OneProcessor | 111.558 ns | 2.9821 ns | 8.5082 ns | 109.311 ns | 0.0063 | - | 40 B |
| BatchProcessor | 263.650 ns | 5.2908 ns | 14.1223 ns | 258.984 ns | 0.0200 | 0.0043 | 128 B |
| TwoProcessors | 108.701 ns | 2.1964 ns | 4.3355 ns | 108.025 ns | 0.0063 | - | 40 B |
| ThreeProcessors | 105.099 ns | 1.8106 ns | 2.1554 ns | 105.796 ns | 0.0063 | - | 40 B |
*/

namespace Benchmarks.Logs;
Expand All @@ -35,11 +36,13 @@ public class LogBenchmarks

private readonly ILogger loggerWithNoListener;
private readonly ILogger loggerWithOneProcessor;
private readonly ILogger loggerWithBatchProcessor;
private readonly ILogger loggerWithTwoProcessors;
private readonly ILogger loggerWithThreeProcessors;

private readonly ILoggerFactory loggerFactoryWithNoListener;
private readonly ILoggerFactory loggerFactoryWithOneProcessor;
private readonly ILoggerFactory loggerFactoryWithBatchProcessor;
private readonly ILoggerFactory loggerFactoryWithTwoProcessor;
private readonly ILoggerFactory loggerFactoryWithThreeProcessor;

Expand All @@ -51,24 +54,31 @@ public LogBenchmarks()
this.loggerFactoryWithOneProcessor = LoggerFactory.Create(builder =>
{
builder.UseOpenTelemetry(logging => logging
.AddProcessor(new DummyLogProcessor()));
.AddProcessor(new NoOpLogProcessor()));
});
this.loggerWithOneProcessor = this.loggerFactoryWithOneProcessor.CreateLogger<LogBenchmarks>();

this.loggerFactoryWithBatchProcessor = LoggerFactory.Create(builder =>
{
builder.UseOpenTelemetry(logging => logging
.AddProcessor(new BatchLogRecordExportProcessor(new NoOpExporter())));
});
this.loggerWithBatchProcessor = this.loggerFactoryWithBatchProcessor.CreateLogger<LogBenchmarks>();

this.loggerFactoryWithTwoProcessor = LoggerFactory.Create(builder =>
{
builder.UseOpenTelemetry(logging => logging
.AddProcessor(new DummyLogProcessor())
.AddProcessor(new DummyLogProcessor()));
.AddProcessor(new NoOpLogProcessor())
.AddProcessor(new NoOpLogProcessor()));
});
this.loggerWithTwoProcessors = this.loggerFactoryWithTwoProcessor.CreateLogger<LogBenchmarks>();

this.loggerFactoryWithThreeProcessor = LoggerFactory.Create(builder =>
{
builder.UseOpenTelemetry(logging => logging
.AddProcessor(new DummyLogProcessor())
.AddProcessor(new DummyLogProcessor())
.AddProcessor(new DummyLogProcessor()));
.AddProcessor(new NoOpLogProcessor())
.AddProcessor(new NoOpLogProcessor())
.AddProcessor(new NoOpLogProcessor()));
});
this.loggerWithThreeProcessors = this.loggerFactoryWithThreeProcessor.CreateLogger<LogBenchmarks>();
}
Expand Down Expand Up @@ -122,6 +132,12 @@ public void OneProcessor()
this.loggerWithOneProcessor.SayHello(FoodName, FoodPrice);
}

[Benchmark]
public void BatchProcessor()
{
this.loggerWithBatchProcessor.SayHello(FoodName, FoodPrice);
}

[Benchmark]
public void TwoProcessors()
{
Expand All @@ -134,7 +150,15 @@ public void ThreeProcessors()
this.loggerWithThreeProcessors.SayHello(FoodName, FoodPrice);
}

internal class DummyLogProcessor : BaseProcessor<LogRecord>
internal class NoOpLogProcessor : BaseProcessor<LogRecord>
{
}

internal class NoOpExporter : BaseExporter<LogRecord>
{
public override ExportResult Export(in Batch<LogRecord> batch)
{
return ExportResult.Success;
}
}
}

0 comments on commit ccd3759

Please sign in to comment.