Update aspnetcore instrumentation benchmarks (#3642)
This commit is contained in:
parent
e68abc8136
commit
faf5bb5dfb
|
|
@ -0,0 +1,34 @@
|
|||
// <copyright file="ValuesController.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>
|
||||
|
||||
#if !NETFRAMEWORK
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Benchmark.Helper
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
public class ValuesController : Controller
|
||||
{
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public IEnumerable<string> Get()
|
||||
{
|
||||
return new string[] { "value1", "value2" };
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
// <copyright file="AspNetCoreInstrumentationBenchmarks.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>
|
||||
|
||||
#if !NETFRAMEWORK
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenTelemetry;
|
||||
using OpenTelemetry.Trace;
|
||||
|
||||
/*
|
||||
// * Summary *
|
||||
|
||||
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000
|
||||
Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
|
||||
.NET SDK=7.0.100-preview.6.22275.1
|
||||
[Host] : .NET 6.0.8 (6.0.822.36306), X64 RyuJIT
|
||||
|
||||
Job=InProcess Toolchain=InProcessEmitToolchain
|
||||
|
||||
| Method | Mean | Error | StdDev | Gen 0 | Allocated |
|
||||
|-------------------------------------------- |---------:|--------:|--------:|-------:|----------:|
|
||||
| UninstrumentedAspNetCoreApp | 155.6 us | 2.63 us | 2.33 us | 0.9766 | 5 KB |
|
||||
| InstrumentedAspNetCoreAppWithDefaultOptions | 176.8 us | 3.24 us | 2.70 us | 1.2207 | 7 KB |
|
||||
*/
|
||||
|
||||
namespace Benchmarks.Instrumentation
|
||||
{
|
||||
[InProcess]
|
||||
public class AspNetCoreInstrumentationBenchmarks
|
||||
{
|
||||
private HttpClient httpClient;
|
||||
private WebApplication app;
|
||||
private TracerProvider tracerProvider;
|
||||
|
||||
[GlobalSetup(Target = nameof(UninstrumentedAspNetCoreApp))]
|
||||
public void UninstrumentedAspNetCoreAppGlobalSetup()
|
||||
{
|
||||
this.StartWebApplication();
|
||||
this.httpClient = new HttpClient();
|
||||
}
|
||||
|
||||
[GlobalSetup(Target = nameof(InstrumentedAspNetCoreAppWithDefaultOptions))]
|
||||
public void InstrumentedAspNetCoreAppWithDefaultOptionsGlobalSetup()
|
||||
{
|
||||
this.StartWebApplication();
|
||||
this.httpClient = new HttpClient();
|
||||
|
||||
this.tracerProvider = Sdk.CreateTracerProviderBuilder()
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.Build();
|
||||
}
|
||||
|
||||
[GlobalCleanup(Target = nameof(UninstrumentedAspNetCoreApp))]
|
||||
public async Task GlobalCleanupUninstrumentedAspNetCoreAppAsync()
|
||||
{
|
||||
this.httpClient.Dispose();
|
||||
await this.app.DisposeAsync();
|
||||
}
|
||||
|
||||
[GlobalCleanup(Target = nameof(InstrumentedAspNetCoreAppWithDefaultOptions))]
|
||||
public async Task GlobalCleanupInstrumentedAspNetCoreAppWithDefaultOptionsAsync()
|
||||
{
|
||||
this.httpClient.Dispose();
|
||||
await this.app.DisposeAsync();
|
||||
this.tracerProvider.Dispose();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public async Task UninstrumentedAspNetCoreApp()
|
||||
{
|
||||
var httpResponse = await this.httpClient.GetAsync("http://localhost:5000/api/values");
|
||||
httpResponse.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public async Task InstrumentedAspNetCoreAppWithDefaultOptions()
|
||||
{
|
||||
var httpResponse = await this.httpClient.GetAsync("http://localhost:5000/api/values");
|
||||
httpResponse.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
private void StartWebApplication()
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder();
|
||||
builder.Services.AddControllers();
|
||||
builder.Logging.ClearProviders();
|
||||
var app = builder.Build();
|
||||
app.MapControllers();
|
||||
app.RunAsync();
|
||||
|
||||
this.app = app;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Loading…
Reference in New Issue