Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="BenchmarkDotNet" Version="0.15.6" />
<PackageReference Include="OpenTelemetry" Version="1.11.2" />
<PackageReference Include="OpenTelemetry.Api" Version="1.11.2" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="BenchmarkDotNet" Version="0.15.6" />
<PackageReference Include="OpenTelemetry.Api" Version="1.11.2" />
</ItemGroup>

Expand Down
12 changes: 10 additions & 2 deletions tracer/test/benchmarks/Benchmarks.Trace/ActivityBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,27 @@ public class ActivityBenchmark

private Datadog.Trace.Activity.DuckTypes.ActivitySource _duckSource;
private ActivitySource _source;
private ActivityListener _activityListener;

[GlobalSetup]
public void GlobalSetup()
{
_source = new ActivitySource(SourceName);

var activityListener = new ActivityListener { ShouldListenTo = _ => true, Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllData };
_activityListener = new ActivityListener { ShouldListenTo = _ => true, Sample = (ref ActivityCreationOptions<ActivityContext> options) => ActivitySamplingResult.AllData };

ActivitySource.AddActivityListener(activityListener);
ActivitySource.AddActivityListener(_activityListener);

_duckSource = new Datadog.Trace.Activity.DuckTypes.ActivitySource { Name = _source.Name, Version = _source.Version ?? string.Empty };
}

[GlobalCleanup]
public void GlobalCleanup()
{
_source.Dispose();
_activityListener.Dispose();
}

[Benchmark]
public void StartStopWithChild()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,9 @@ public void GlobalSetup()

_enrichedSpans = new ArraySegment<Span>(enrichedSpans);

var overrides = new NameValueConfigurationSource(new()
{
{ ConfigurationKeys.StartupDiagnosticLogEnabled, false.ToString() },
{ ConfigurationKeys.TraceEnabled, false.ToString() },
});
var sources = new CompositeConfigurationSource(new[] { overrides, GlobalConfigurationSource.Instance });
var settings = new TracerSettings(sources);
var config = TracerHelper.DefaultConfig;
config.Add(ConfigurationKeys.TraceEnabled, false);
var settings = TracerSettings.Create(config);

var api = new Api(new FakeApiRequestFactory(settings.Exporter.AgentUri), statsd: null, updateSampleRates: null, partialFlushEnabled: false);

Expand All @@ -55,6 +51,12 @@ public void GlobalSetup()
WriteAndFlushEnrichedTraces().GetAwaiter().GetResult();
}

[GlobalCleanup]
public void GlobalCleanup()
{
_agentWriter.FlushAndCloseAsync();
}

/// <summary>
/// Same as WriteAndFlushTraces but with more realistic traces (with tags and metrics)
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,27 @@ internal class AppSecBenchmarkUtils
{
internal static void SetupDummyAgent()
{
var settings = TracerSettings.Create(new()
TracerHelper.SetGlobalTracer(new()
{
{ ConfigurationKeys.StartupDiagnosticLogEnabled, false },
#pragma warning disable CS0618 // Type or member is obsolete
{ ConfigurationKeys.MaxTracesSubmittedPerSecond, 0 },
#pragma warning restore CS0618 // Type or member is obsolete
{ ConfigurationKeys.Rcm.RemoteConfigurationEnabled, false }, // disable remote config
{ ConfigurationKeys.AgentFeaturePollingEnabled, false }, // disable discovery service
{ ConfigurationKeys.Telemetry.Enabled, false }, // disable telemetry
});
Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));
}

internal static void CleanupDummyAgent()
{
TracerHelper.CleanupGlobalTracer();
}

internal static void CleanupWafLibraryInvoker()
{
Environment.SetEnvironmentVariable("DD_TRACE_LOGGING_RATE", null);
Environment.SetEnvironmentVariable("DD_INTERNAL_TRACE_NATIVE_ENGINE_PATH", null);
}

internal static WafLibraryInvoker CreateWafLibraryInvoker()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class AppSecBodyBenchmark
public void GlobalSetup()
{
AppSecBenchmarkUtils.SetupDummyAgent();
var dir = Directory.GetCurrentDirectory();
Environment.SetEnvironmentVariable("DD_APPSEC_ENABLED", "true");
_security = Security.Instance;

Expand Down Expand Up @@ -73,6 +72,13 @@ public void GlobalSetup()
_props10x6 = ConstructionUtils.ConstructProps10Rec(6);
}

[GlobalCleanup]
public void GlobalCleanup()
{
Environment.SetEnvironmentVariable("DD_APPSEC_ENABLED", null);
AppSecBenchmarkUtils.CleanupDummyAgent();
}

[Benchmark]
public void AllCycleSimpleBody() => ExecuteCycle(new { });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ public void GlobalSetup()
_args = MakeNestedMap(20);
}

[GlobalCleanup]
public void GlobalCleanup()
{
AppSecBenchmarkUtils.CleanupDummyAgent();
AppSecBenchmarkUtils.CleanupWafLibraryInvoker();
if (Encoder.Pool is { IsDisposed: false } pool)
{
pool.Dispose();
}
}

/// <summary>
/// Generates dummy arguments for the waf
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public void GlobalSetup()
_stage3 = MakeRealisticNestedMapStage3();
}

[GlobalCleanup]
public void GlobalCleanup()
{
AppSecBenchmarkUtils.CleanupDummyAgent();
AppSecBenchmarkUtils.CleanupWafLibraryInvoker();
_waf?.Dispose();
}

[IterationSetup]
public void IterationSetup()
{
Expand Down
47 changes: 42 additions & 5 deletions tracer/test/benchmarks/Benchmarks.Trace/AspNetCoreBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#if !NETFRAMEWORK

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using Datadog.Trace;
using Datadog.Trace.Agent.DiscoveryService;
using Datadog.Trace.AppSec;
using Datadog.Trace.ClrProfiler.AutoInstrumentation.Http.HttpClient.HttpClientHandler;
using Datadog.Trace.Configuration;
using Datadog.Trace.Configuration.Telemetry;
using Datadog.Trace.Debugger;
using Datadog.Trace.Debugger.SpanCodeOrigin;
using Datadog.Trace.DiagnosticListeners;
using Datadog.Trace.Iast.Settings;
using Datadog.Trace.RemoteConfigurationManagement;
using Datadog.Trace.Security.Unit.Tests.Iast;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -22,26 +32,48 @@ namespace Benchmarks.Trace
public class AspNetCoreBenchmark
{
private HttpClient _client;
private Tracer _tracer;
private Security _security;
private Datadog.Trace.Iast.Iast _iast;
private SpanCodeOrigin _spanCodeOrigin;
private DiagnosticManager _diagnosticManager;
private TestServer _testServer;

[GlobalSetup]
public void GlobalSetup()
{
var settings = TracerSettings.Create(new() { { ConfigurationKeys.StartupDiagnosticLogEnabled, false } });
var config = new CustomSettingsForTests(TracerHelper.DefaultConfig);
var settings = new TracerSettings(config, NullConfigurationTelemetry.Instance, new());

Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));
_tracer = TracerHelper.CreateTracer(settings);
_security = new Security(new SecuritySettings(config, NullConfigurationTelemetry.Instance), null, new RcmSubscriptionManager());
_iast = new Datadog.Trace.Iast.Iast(new IastSettings(config, NullConfigurationTelemetry.Instance), NullDiscoveryService.Instance);

var builder = new WebHostBuilder()
.UseStartup<Startup>();

var testServer = new TestServer(builder);
_client = testServer.CreateClient();
_testServer = new TestServer(builder);
_client = _testServer.CreateClient();

Datadog.Trace.ClrProfiler.Instrumentation.Initialize();
var observers = new List<DiagnosticObserver>();
_spanCodeOrigin = new SpanCodeOrigin(new DebuggerSettings(config, NullConfigurationTelemetry.Instance));
observers.Add(new AspNetCoreDiagnosticObserver(_tracer, _security, _iast, _spanCodeOrigin));
_diagnosticManager = new DiagnosticManager(observers);
_diagnosticManager.Start();

// Warmup to initialize middleware pipeline
SendRequest();
}

[GlobalCleanup]
public void GlobalCleanup()
{
_diagnosticManager.Dispose();
_testServer.Dispose();
_security.Dispose();
_tracer.TracerManager.ShutdownAsync().GetAwaiter().GetResult();
}

[Benchmark]
public string SendRequest()
{
Expand Down Expand Up @@ -102,6 +134,11 @@ public void GlobalSetup()
{
}

[GlobalCleanup]
public void GlobalCleanup()
{
}

[Benchmark]
public string SendRequest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="JetBrains.Profiler.SelfApi" Version="2.4.2" />
<PackageReference Include="BenchmarkDotNet" Version="0.15.6" />
<PackageReference Include="JetBrains.Profiler.SelfApi" Version="2.5.14" />
<PackageReference Include="log4net" Version="2.0.12" />
<PackageReference Include="NLog" Version="5.2.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.18" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="7.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,23 @@ public void GlobalSetup()

_enrichedSpans = new ArraySegment<Span>(enrichedSpans);

var overrides = new NameValueConfigurationSource(new()
{
{ ConfigurationKeys.StartupDiagnosticLogEnabled, false.ToString() },
{ ConfigurationKeys.TraceEnabled, false.ToString() },
});
var sources = new CompositeConfigurationSource(new[] { overrides, GlobalConfigurationSource.Instance });
var settings = new TestOptimizationSettings(sources, NullConfigurationTelemetry.Instance);
var config = TracerHelper.DefaultConfig;
config[ConfigurationKeys.TraceEnabled] = false;
var settings = new TestOptimizationSettings(new DictionaryObjectConfigurationSource(config), NullConfigurationTelemetry.Instance);

_eventWriter = new CIVisibilityProtocolWriter(settings, new FakeCIVisibilityProtocolWriter());

// Warmup to reduce noise
WriteAndFlushEnrichedTraces().GetAwaiter().GetResult();
}

[GlobalCleanup]
public void GlobalCleanup()
{
_eventWriter.FlushAndCloseAsync();
}


/// <summary>
/// Same as WriteAndFlushTraces but with more realistic traces (with tags and metrics)
/// </summary>
Expand Down
11 changes: 7 additions & 4 deletions tracer/test/benchmarks/Benchmarks.Trace/DbCommandBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ public class DbCommandBenchmark
[GlobalSetup]
public void GlobalSetup()
{
var settings = TracerSettings.Create(new() { { ConfigurationKeys.StartupDiagnosticLogEnabled, false } });

Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));

TracerHelper.SetGlobalTracer();
_customCommand = new CustomDbCommand();
}

[GlobalCleanup]
public void GlobalCleanup()
{
TracerHelper.CleanupGlobalTracer();
}

[Benchmark]
public unsafe int ExecuteNonQuery()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public class ElasticsearchBenchmark
[GlobalSetup]
public void GlobalSetup()
{
var settings = TracerSettings.Create(new() { { ConfigurationKeys.StartupDiagnosticLogEnabled, false } });

Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));
TracerHelper.SetGlobalTracer();

_pipeline = new RequestPipeline();
_data = new RequestData
Expand All @@ -33,6 +31,12 @@ public void GlobalSetup()
};
}

[GlobalCleanup]
public void GlobalCleanup()
{
TracerHelper.CleanupGlobalTracer();
}

[Benchmark]
public unsafe object CallElasticsearch()
{
Expand Down
10 changes: 7 additions & 3 deletions tracer/test/benchmarks/Benchmarks.Trace/GraphQLBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ public class GraphQLBenchmark
[GlobalSetup]
public void GlobalSetup()
{
var settings = TracerSettings.Create(new() { { ConfigurationKeys.StartupDiagnosticLogEnabled, false } });

Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));
TracerHelper.SetGlobalTracer();

_context = new ExecutionContext();
_client = new GraphQLClient(_result);
}

[GlobalCleanup]
public void GlobalCleanup()
{
TracerHelper.CleanupGlobalTracer();
}

[Benchmark]
public unsafe int ExecuteAsync()
{
Expand Down
12 changes: 8 additions & 4 deletions tracer/test/benchmarks/Benchmarks.Trace/HttpClientBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ public class HttpClientBenchmark
[GlobalSetup]
public void GlobalSetup()
{
var settings = TracerSettings.Create(new() { { ConfigurationKeys.StartupDiagnosticLogEnabled, false } });

Tracer.UnsafeSetTracerInstance(new Tracer(settings, new DummyAgentWriter(), null, null, null));

TracerHelper.SetGlobalTracer();
_httpRequest = new HttpRequestMessage { RequestUri = new Uri("http://datadoghq.com") };
}

[GlobalCleanup]
public void GlobalCleanup()
{
TracerHelper.CleanupGlobalTracer();
_httpRequest.Dispose();
}

[Benchmark]
public unsafe string SendAsync()
{
Expand Down
Loading
Loading