Validate benchmarks (#2126)

This commit is contained in:
Pavel Krymets 2017-10-23 09:51:00 -07:00 committed by GitHub
parent 3fbfba63f8
commit fff3e1ebd0
15 changed files with 90 additions and 67 deletions

View File

@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [ParameterizedJobConfig(typeof(CoreConfig))]
public class DotSegmentRemovalBenchmark public class DotSegmentRemovalBenchmark
{ {
// Immutable // Immutable

View File

@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [ParameterizedJobConfig(typeof(CoreConfig))]
public class Http1ConnectionParsingOverheadBenchmark public class Http1ConnectionParsingOverheadBenchmark
{ {
private const int InnerLoopCount = 512; private const int InnerLoopCount = 512;
@ -22,20 +22,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
[IterationSetup] [IterationSetup]
public void Setup() public void Setup()
{ {
var pipeFactory = new PipeFactory();
var pair = pipeFactory.CreateConnectionPair();
var serviceContext = new ServiceContext var serviceContext = new ServiceContext
{ {
HttpParserFactory = _ => NullParser<Http1ParsingHandler>.Instance, ServerOptions = new KestrelServerOptions(),
ServerOptions = new KestrelServerOptions() HttpParserFactory = f => NullParser<Http1ParsingHandler>.Instance
}; };
var http1ConnectionContext = new Http1ConnectionContext
var http1Connection = new Http1Connection<object>(application: null, context: new Http1ConnectionContext
{ {
ServiceContext = serviceContext, ServiceContext = serviceContext,
ConnectionFeatures = new FeatureCollection(), ConnectionFeatures = new FeatureCollection(),
PipeFactory = new PipeFactory(), PipeFactory = pipeFactory,
TimeoutControl = new MockTimeoutControl() TimeoutControl = new MockTimeoutControl(),
}; Application = pair.Application,
Transport = pair.Transport
});
_http1Connection = new Http1Connection<object>(application: null, context: http1ConnectionContext); http1Connection.Reset();
_http1Connection = http1Connection;
} }
[Benchmark(Baseline = true, OperationsPerInvoke = InnerLoopCount)] [Benchmark(Baseline = true, OperationsPerInvoke = InnerLoopCount)]

View File

@ -15,7 +15,7 @@ using Microsoft.AspNetCore.Testing;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [ParameterizedJobConfig(typeof(CoreConfig))]
public class Http1WritingBenchmark public class Http1WritingBenchmark
{ {
// Standard completed task // Standard completed task

View File

@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [ParameterizedJobConfig(typeof(CoreConfig))]
public class HttpParserBenchmark : IHttpRequestLineHandler, IHttpHeadersHandler public class HttpParserBenchmark : IHttpRequestLineHandler, IHttpHeadersHandler
{ {

View File

@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [ParameterizedJobConfig(typeof(CoreConfig))]
public class HttpProtocolFeatureCollection public class HttpProtocolFeatureCollection
{ {
private readonly Http1Connection<object> _http1Connection; private readonly Http1Connection<object> _http1Connection;
@ -77,19 +77,29 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
public HttpProtocolFeatureCollection() public HttpProtocolFeatureCollection()
{ {
var pipeFactory = new PipeFactory();
var pair = pipeFactory.CreateConnectionPair();
var serviceContext = new ServiceContext var serviceContext = new ServiceContext
{ {
HttpParserFactory = _ => NullParser<Http1ParsingHandler>.Instance, DateHeaderValueManager = new DateHeaderValueManager(),
ServerOptions = new KestrelServerOptions() ServerOptions = new KestrelServerOptions(),
Log = new MockTrace(),
HttpParserFactory = f => new HttpParser<Http1ParsingHandler>()
}; };
var http1ConnectionContext = new Http1ConnectionContext
var http1Connection = new Http1Connection<object>(application: null, context: new Http1ConnectionContext
{ {
ServiceContext = serviceContext, ServiceContext = serviceContext,
ConnectionFeatures = new FeatureCollection(), ConnectionFeatures = new FeatureCollection(),
PipeFactory = new PipeFactory() PipeFactory = pipeFactory,
}; Application = pair.Application,
Transport = pair.Transport
});
_http1Connection = new Http1Connection<object>(application: null, context: http1ConnectionContext); http1Connection.Reset();
_http1Connection = http1Connection;
} }
[IterationSetup] [IterationSetup]

View File

@ -4,8 +4,7 @@
<!-- Using shorter assembly name instead of Microsoft.AspNetCore.Server.Kestrel.Performance because https://github.com/dotnet/BenchmarkDotNet/issues/498 --> <!-- Using shorter assembly name instead of Microsoft.AspNetCore.Server.Kestrel.Performance because https://github.com/dotnet/BenchmarkDotNet/issues/498 -->
<AssemblyName>Kestrel.Performance</AssemblyName> <AssemblyName>Kestrel.Performance</AssemblyName>
<RootNamespace>Microsoft.AspNetCore.Server.Kestrel.Performance</RootNamespace> <RootNamespace>Microsoft.AspNetCore.Server.Kestrel.Performance</RootNamespace>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks> <TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netcoreapp2.0</TargetFrameworks>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<ServerGarbageCollection>true</ServerGarbageCollection> <ServerGarbageCollection>true</ServerGarbageCollection>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@ -24,6 +23,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.10.9" NoWarn="KRB4002" /> <PackageReference Include="BenchmarkDotNet" Version="0.10.9" NoWarn="KRB4002" />
<PackageReference Include="Microsoft.AspNetCore.BenchmarkRunner.Sources" PrivateAssets="All" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[ParameterizedJobConfig(typeof(CoreConfig))]
public class KnownStringsBenchmark public class KnownStringsBenchmark
{ {
static byte[] _methodConnect = Encoding.ASCII.GetBytes("CONNECT "); static byte[] _methodConnect = Encoding.ASCII.GetBytes("CONNECT ");

View File

@ -7,7 +7,7 @@ using BenchmarkDotNet.Attributes;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [ParameterizedJobConfig(typeof(CoreConfig))]
public class PipeThroughputBenchmark public class PipeThroughputBenchmark
{ {
private const int _writeLenght = 57; private const int _writeLenght = 57;

View File

@ -1,16 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Reflection;
using BenchmarkDotNet.Running;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{
public class Program
{
public static void Main(string[] args)
{
BenchmarkSwitcher.FromAssembly(typeof(Program).GetTypeInfo().Assembly).Run(args);
}
}
}

View File

@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Performance.Mocks;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [ParameterizedJobConfig(typeof(CoreConfig))]
public class RequestParsingBenchmark public class RequestParsingBenchmark
{ {
public IPipe Pipe { get; set; } public IPipe Pipe { get; set; }
@ -23,23 +23,31 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
[IterationSetup] [IterationSetup]
public void Setup() public void Setup()
{ {
PipeFactory = new PipeFactory(); var pipeFactory = new PipeFactory();
Pipe = PipeFactory.Create(); var pair = pipeFactory.CreateConnectionPair();
var serviceContext = new ServiceContext var serviceContext = new ServiceContext
{ {
HttpParserFactory = f => new HttpParser<Http1ParsingHandler>(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = new MockTrace(),
HttpParserFactory = f => new HttpParser<Http1ParsingHandler>()
}; };
var http1ConnectionContext = new Http1ConnectionContext
var http1Connection = new Http1Connection<object>(application: null, context: new Http1ConnectionContext
{ {
ServiceContext = serviceContext, ServiceContext = serviceContext,
ConnectionFeatures = new FeatureCollection(), ConnectionFeatures = new FeatureCollection(),
PipeFactory = PipeFactory, PipeFactory = pipeFactory,
Application = pair.Application,
Transport = pair.Transport,
TimeoutControl = new MockTimeoutControl() TimeoutControl = new MockTimeoutControl()
}; });
Http1Connection = new Http1Connection<object>(application: null, context: http1ConnectionContext); http1Connection.Reset();
Http1Connection = http1Connection;
Pipe = pipeFactory.Create();
} }
[Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)] [Benchmark(Baseline = true, OperationsPerInvoke = RequestParsingData.InnerLoopCount)]

View File

@ -14,7 +14,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [ParameterizedJobConfig(typeof(CoreConfig))]
public class ResponseHeaderCollectionBenchmark public class ResponseHeaderCollectionBenchmark
{ {
private const int InnerLoopCount = 512; private const int InnerLoopCount = 512;
@ -170,21 +170,28 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
[IterationSetup] [IterationSetup]
public void Setup() public void Setup()
{ {
var pipeFactory = new PipeFactory();
var pair = pipeFactory.CreateConnectionPair();
var serviceContext = new ServiceContext var serviceContext = new ServiceContext
{ {
HttpParserFactory = f => new HttpParser<Http1ParsingHandler>(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerOptions = new KestrelServerOptions() ServerOptions = new KestrelServerOptions(),
Log = new MockTrace(),
HttpParserFactory = f => new HttpParser<Http1ParsingHandler>()
}; };
var http1ConnectionContext = new Http1ConnectionContext
var http1Connection = new Http1Connection<object>(application: null, context: new Http1ConnectionContext
{ {
ServiceContext = serviceContext, ServiceContext = serviceContext,
ConnectionFeatures = new FeatureCollection(), ConnectionFeatures = new FeatureCollection(),
PipeFactory = new PipeFactory() PipeFactory = pipeFactory,
}; Application = pair.Application,
Transport = pair.Transport
var http1Connection = new Http1Connection<object>(application: null, context: http1ConnectionContext); });
http1Connection.Reset(); http1Connection.Reset();
_responseHeadersDirect = (HttpResponseHeaders)http1Connection.ResponseHeaders; _responseHeadersDirect = (HttpResponseHeaders)http1Connection.ResponseHeaders;
var context = new DefaultHttpContext(http1Connection); var context = new DefaultHttpContext(http1Connection);
_response = new DefaultHttpResponse(context); _response = new DefaultHttpResponse(context);

View File

@ -16,7 +16,7 @@ using Microsoft.AspNetCore.Testing;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [ParameterizedJobConfig(typeof(CoreConfig))]
public class ResponseHeadersWritingBenchmark public class ResponseHeadersWritingBenchmark
{ {
private static readonly byte[] _helloWorldPayload = Encoding.ASCII.GetBytes("Hello, World!"); private static readonly byte[] _helloWorldPayload = Encoding.ASCII.GetBytes("Hello, World!");

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [ParameterizedJobConfig(typeof(CoreConfig))]
public class StringUtilitiesBenchmark public class StringUtilitiesBenchmark
{ {
private const int Iterations = 500_000; private const int Iterations = 500_000;

View File

@ -12,20 +12,25 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
public class CoreConfig : ManualConfig public class CoreConfig : ManualConfig
{ {
public CoreConfig() public CoreConfig() : this(Job.Core
{
Add(JitOptimizationsValidator.FailOnError);
Add(MemoryDiagnoser.Default);
Add(StatisticColumn.OperationsPerSecond);
Add(Job.Default
.With(BenchmarkDotNet.Environments.Runtime.Core)
.WithRemoveOutliers(false) .WithRemoveOutliers(false)
.With(new GcMode() { Server = true }) .With(new GcMode() { Server = true })
.With(RunStrategy.Throughput) .With(RunStrategy.Throughput)
.WithLaunchCount(3) .WithLaunchCount(3)
.WithWarmupCount(5) .WithWarmupCount(5)
.WithTargetCount(10)); .WithTargetCount(10))
{
Add(JitOptimizationsValidator.FailOnError);
}
public CoreConfig(Job job)
{
Add(DefaultConfig.Instance);
Add(MemoryDiagnoser.Default);
Add(StatisticColumn.OperationsPerSecond);
Add(job);
} }
} }
} }

View File

@ -1,8 +1,8 @@
<Project> <Project>
<PropertyGroup>
<EnableBenchmarkValidation>true</EnableBenchmarkValidation>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<!-- required for the custom version of csc -->
<DotNetCoreRuntime Include="1.1.2" />
<PackageLineup Include="Internal.AspNetCore.Universe.Lineup" Version="2.1.0-*" /> <PackageLineup Include="Internal.AspNetCore.Universe.Lineup" Version="2.1.0-*" />
<PackageLineup Include="Internal.AspNetCore.Partners.Lineup" Version="2.1.0-*" /> <PackageLineup Include="Internal.AspNetCore.Partners.Lineup" Version="2.1.0-*" />
</ItemGroup> </ItemGroup>