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

Tweaks to ActivityCreation benchmarks #5173

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
25 changes: 13 additions & 12 deletions test/Benchmarks/Helper/ActivityCreationScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
{
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)
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
{
using var activity = source.StartActivity("name");
activity?.AddTag("tag1", "string");
activity?.AddTag("tag2", 1);
activity?.AddTag("tag3", true);
activity?.SetTag("tag4", "string-again");
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
activity?.SetTag("tag5", "string-more");
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
activity?.Stop();
}
}
28 changes: 14 additions & 14 deletions test/Benchmarks/Trace/ActivityCreationBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
|----------------------------------------------- |----------:|---------:|----------:|----------:|
| 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;
Expand All @@ -30,14 +29,14 @@ 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]
public void GlobalSetup()
{
this.tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("BenchMark")
.AddProcessor(new NoopActivityProcessor())
.Build();
}

Expand All @@ -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);
cijothomas marked this conversation as resolved.
Show resolved Hide resolved

[Benchmark]
public void CreateActivity_WithAttributes_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithAttributes(this.benchmarkSource);
public void CreateActivity_WithAddAttributes_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithAddAttributes(this.benchmarkSource);
cijothomas marked this conversation as resolved.
Show resolved Hide resolved

[Benchmark]
public void CreateActivity_WithKind_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithKind(this.benchmarkSource);
internal class NoopActivityProcessor : BaseProcessor<Activity>
{
}
}