From d853d1d8ea724a4798851d49b9b7ca49787ea79c Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Wed, 13 Dec 2023 17:20:39 -0800 Subject: [PATCH 1/4] Tweaks to ActivityCreation benchmarks --- .../Helper/ActivityCreationScenarios.cs | 25 +++++++++-------- .../Trace/ActivityCreationBenchmarks.cs | 28 +++++++++---------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/test/Benchmarks/Helper/ActivityCreationScenarios.cs b/test/Benchmarks/Helper/ActivityCreationScenarios.cs index 6b1b9f2a1b4..bbf4c3a338b 100644 --- a/test/Benchmarks/Helper/ActivityCreationScenarios.cs +++ b/test/Benchmarks/Helper/ActivityCreationScenarios.cs @@ -13,30 +13,31 @@ public static void CreateActivity(ActivitySource source) activity?.Stop(); } - public static void CreateActivityWithKind(ActivitySource source) - { - using var activity = source.StartActivity("name", ActivityKind.Client); - activity?.Stop(); - } - public static void CreateActivityFromParentContext(ActivitySource source, ActivityContext parentCtx) { using var activity = source.StartActivity("name", ActivityKind.Internal, parentCtx); activity?.Stop(); } - public static void CreateActivityFromParentId(ActivitySource source, string parentId) - { - using var activity = source.StartActivity("name", ActivityKind.Internal, parentId); - activity?.Stop(); - } - public static void CreateActivityWithAttributes(ActivitySource source) { using var activity = source.StartActivity("name"); activity?.SetTag("tag1", "string"); activity?.SetTag("tag2", 1); activity?.SetTag("tag3", true); + activity?.SetTag("tag4", "string-again"); + activity?.SetTag("tag5", "string-more"); + activity?.Stop(); + } + + public static void CreateActivityWithAddAttributes(ActivitySource source) + { + using var activity = source.StartActivity("name"); + activity?.AddTag("tag1", "string"); + activity?.AddTag("tag2", 1); + activity?.AddTag("tag3", true); + activity?.SetTag("tag4", "string-again"); + activity?.SetTag("tag5", "string-more"); activity?.Stop(); } } diff --git a/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs b/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs index b7c30f1212a..d8f7815acdc 100644 --- a/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs +++ b/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs @@ -8,20 +8,19 @@ using OpenTelemetry.Trace; /* -BenchmarkDotNet v0.13.10, Windows 11 (10.0.23424.1000) -Intel Core i7-9700 CPU 3.00GHz, 1 CPU, 8 logical and 8 physical cores +BenchmarkDotNet v0.13.10, Windows 11 (10.0.22621.2861) +11th Gen Intel Core i7-1185G7 3.00GHz, 1 CPU, 8 logical and 4 physical cores .NET SDK 8.0.100 [Host] : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2 DefaultJob : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2 -| Method | Mean | Error | StdDev | Gen0 | Allocated | -|----------------------------------------------- |----------:|---------:|---------:|-------:|----------:| -| CreateActivity_NoopProcessor | 307.12 ns | 5.769 ns | 6.172 ns | 0.0663 | 416 B | -| CreateActivity_WithParentContext_NoopProcessor | 75.18 ns | 0.399 ns | 0.354 ns | - | - | -| CreateActivity_WithParentId_NoopProcessor | 156.52 ns | 1.609 ns | 1.426 ns | 0.0229 | 144 B | -| CreateActivity_WithAttributes_NoopProcessor | 372.34 ns | 6.215 ns | 4.852 ns | 0.0992 | 624 B | -| CreateActivity_WithKind_NoopProcessor | 302.24 ns | 5.859 ns | 8.402 ns | 0.0663 | 416 B | +| Method | Mean | Error | StdDev | Median | +|----------------------------------------------- |----------:|---------:|----------:|----------:| +| CreateActivity_NoopProcessor | 245.32 ns | 4.934 ns | 10.408 ns | 239.75 ns | +| CreateActivity_WithParentContext_NoopProcessor | 53.81 ns | 1.090 ns | 1.850 ns | 53.48 ns | +| CreateActivity_WithSetAttributes_NoopProcessor | 363.87 ns | 7.200 ns | 16.830 ns | 367.81 ns | +| CreateActivity_WithAddAttributes_NoopProcessor | 340.51 ns | 2.072 ns | 1.731 ns | 340.35 ns | */ namespace Benchmarks.Trace; @@ -30,7 +29,6 @@ public class ActivityCreationBenchmarks { private readonly ActivitySource benchmarkSource = new("Benchmark"); private readonly ActivityContext parentCtx = new(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None); - private readonly string parentId = $"00-{ActivityTraceId.CreateRandom()}.{ActivitySpanId.CreateRandom()}.00"; private TracerProvider tracerProvider; [GlobalSetup] @@ -38,6 +36,7 @@ public void GlobalSetup() { this.tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource("BenchMark") + .AddProcessor(new NoopActivityProcessor()) .Build(); } @@ -55,11 +54,12 @@ public void GlobalCleanup() public void CreateActivity_WithParentContext_NoopProcessor() => ActivityCreationScenarios.CreateActivityFromParentContext(this.benchmarkSource, this.parentCtx); [Benchmark] - public void CreateActivity_WithParentId_NoopProcessor() => ActivityCreationScenarios.CreateActivityFromParentId(this.benchmarkSource, this.parentId); + public void CreateActivity_WithSetAttributes_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithAttributes(this.benchmarkSource); [Benchmark] - public void CreateActivity_WithAttributes_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithAttributes(this.benchmarkSource); + public void CreateActivity_WithAddAttributes_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithAddAttributes(this.benchmarkSource); - [Benchmark] - public void CreateActivity_WithKind_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithKind(this.benchmarkSource); + internal class NoopActivityProcessor : BaseProcessor + { + } } From 2c54609166e1265d05f39f40049305c3f48fa0c2 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Wed, 13 Dec 2023 18:27:31 -0800 Subject: [PATCH 2/4] use set --- test/Benchmarks/Helper/ActivityCreationScenarios.cs | 4 ++-- test/Benchmarks/Trace/ActivityCreationBenchmarks.cs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/Benchmarks/Helper/ActivityCreationScenarios.cs b/test/Benchmarks/Helper/ActivityCreationScenarios.cs index bbf4c3a338b..cce24e0acac 100644 --- a/test/Benchmarks/Helper/ActivityCreationScenarios.cs +++ b/test/Benchmarks/Helper/ActivityCreationScenarios.cs @@ -36,8 +36,8 @@ public static void CreateActivityWithAddAttributes(ActivitySource source) activity?.AddTag("tag1", "string"); activity?.AddTag("tag2", 1); activity?.AddTag("tag3", true); - activity?.SetTag("tag4", "string-again"); - activity?.SetTag("tag5", "string-more"); + activity?.AddTag("tag4", "string-again"); + activity?.AddTag("tag5", "string-more"); activity?.Stop(); } } diff --git a/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs b/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs index d8f7815acdc..0581de64a16 100644 --- a/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs +++ b/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs @@ -17,10 +17,10 @@ .NET SDK 8.0.100 | Method | Mean | Error | StdDev | Median | |----------------------------------------------- |----------:|---------:|----------:|----------:| -| CreateActivity_NoopProcessor | 245.32 ns | 4.934 ns | 10.408 ns | 239.75 ns | -| CreateActivity_WithParentContext_NoopProcessor | 53.81 ns | 1.090 ns | 1.850 ns | 53.48 ns | -| CreateActivity_WithSetAttributes_NoopProcessor | 363.87 ns | 7.200 ns | 16.830 ns | 367.81 ns | -| CreateActivity_WithAddAttributes_NoopProcessor | 340.51 ns | 2.072 ns | 1.731 ns | 340.35 ns | +| CreateActivity_NoopProcessor | 247.22 ns | 4.977 ns | 13.198 ns | 240.34 ns | +| CreateActivity_WithParentContext_NoopProcessor | 55.17 ns | 1.131 ns | 1.111 ns | 54.98 ns | +| CreateActivity_WithSetAttributes_NoopProcessor | 333.13 ns | 2.415 ns | 1.885 ns | 332.76 ns | +| CreateActivity_WithAddAttributes_NoopProcessor | 339.23 ns | 6.686 ns | 10.210 ns | 335.73 ns | */ namespace Benchmarks.Trace; From 5dfb4ee0280f1efb00aa9d12a1574dc73e817214 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Wed, 13 Dec 2023 18:28:31 -0800 Subject: [PATCH 3/4] rename --- test/Benchmarks/Helper/ActivityCreationScenarios.cs | 2 +- test/Benchmarks/Trace/ActivityCreationBenchmarks.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Benchmarks/Helper/ActivityCreationScenarios.cs b/test/Benchmarks/Helper/ActivityCreationScenarios.cs index cce24e0acac..cffd4d30e27 100644 --- a/test/Benchmarks/Helper/ActivityCreationScenarios.cs +++ b/test/Benchmarks/Helper/ActivityCreationScenarios.cs @@ -19,7 +19,7 @@ public static void CreateActivityFromParentContext(ActivitySource source, Activi activity?.Stop(); } - public static void CreateActivityWithAttributes(ActivitySource source) + public static void CreateActivityWithSetAttributes(ActivitySource source) { using var activity = source.StartActivity("name"); activity?.SetTag("tag1", "string"); diff --git a/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs b/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs index 0581de64a16..e596673c14a 100644 --- a/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs +++ b/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs @@ -54,7 +54,7 @@ public void GlobalCleanup() public void CreateActivity_WithParentContext_NoopProcessor() => ActivityCreationScenarios.CreateActivityFromParentContext(this.benchmarkSource, this.parentCtx); [Benchmark] - public void CreateActivity_WithSetAttributes_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithAttributes(this.benchmarkSource); + public void CreateActivity_WithSetAttributes_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithSetAttributes(this.benchmarkSource); [Benchmark] public void CreateActivity_WithAddAttributes_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithAddAttributes(this.benchmarkSource); From f47a02b558bab593f4f2b63d225d8344c59ee36e Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Wed, 13 Dec 2023 18:41:30 -0800 Subject: [PATCH 4/4] rename and rerun --- test/Benchmarks/Helper/ActivityCreationScenarios.cs | 4 ++-- test/Benchmarks/Trace/ActivityCreationBenchmarks.cs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/Benchmarks/Helper/ActivityCreationScenarios.cs b/test/Benchmarks/Helper/ActivityCreationScenarios.cs index cffd4d30e27..48c67b4c3d4 100644 --- a/test/Benchmarks/Helper/ActivityCreationScenarios.cs +++ b/test/Benchmarks/Helper/ActivityCreationScenarios.cs @@ -19,7 +19,7 @@ public static void CreateActivityFromParentContext(ActivitySource source, Activi activity?.Stop(); } - public static void CreateActivityWithSetAttributes(ActivitySource source) + public static void CreateActivityWithSetTags(ActivitySource source) { using var activity = source.StartActivity("name"); activity?.SetTag("tag1", "string"); @@ -30,7 +30,7 @@ public static void CreateActivityWithSetAttributes(ActivitySource source) activity?.Stop(); } - public static void CreateActivityWithAddAttributes(ActivitySource source) + public static void CreateActivityWithAddTags(ActivitySource source) { using var activity = source.StartActivity("name"); activity?.AddTag("tag1", "string"); diff --git a/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs b/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs index e596673c14a..447e550bd87 100644 --- a/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs +++ b/test/Benchmarks/Trace/ActivityCreationBenchmarks.cs @@ -19,8 +19,8 @@ .NET SDK 8.0.100 |----------------------------------------------- |----------:|---------:|----------:|----------:| | CreateActivity_NoopProcessor | 247.22 ns | 4.977 ns | 13.198 ns | 240.34 ns | | CreateActivity_WithParentContext_NoopProcessor | 55.17 ns | 1.131 ns | 1.111 ns | 54.98 ns | -| CreateActivity_WithSetAttributes_NoopProcessor | 333.13 ns | 2.415 ns | 1.885 ns | 332.76 ns | -| CreateActivity_WithAddAttributes_NoopProcessor | 339.23 ns | 6.686 ns | 10.210 ns | 335.73 ns | +| CreateActivity_WithSetTags_NoopProcessor | 375.2 ns | 7.52 ns | 18.44 ns | 370.4 ns | +| CreateActivity_WithAddTags_NoopProcessor | 340.9 ns | 6.27 ns | 12.81 ns | 336.1 ns | */ namespace Benchmarks.Trace; @@ -54,10 +54,10 @@ public void GlobalCleanup() public void CreateActivity_WithParentContext_NoopProcessor() => ActivityCreationScenarios.CreateActivityFromParentContext(this.benchmarkSource, this.parentCtx); [Benchmark] - public void CreateActivity_WithSetAttributes_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithSetAttributes(this.benchmarkSource); + public void CreateActivity_WithSetTags_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithSetTags(this.benchmarkSource); [Benchmark] - public void CreateActivity_WithAddAttributes_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithAddAttributes(this.benchmarkSource); + public void CreateActivity_WithAddTags_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithAddTags(this.benchmarkSource); internal class NoopActivityProcessor : BaseProcessor {