Move perf, share code

This commit is contained in:
Ben Adams 2016-11-19 04:33:08 +00:00
parent 5041d6c291
commit 8ce47fb8b6
19 changed files with 68 additions and 246 deletions

View File

@ -37,7 +37,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC
test\shared\DummyApplication.cs = test\shared\DummyApplication.cs
test\shared\HttpClientSlim.cs = test\shared\HttpClientSlim.cs
test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.cs
test\shared\MockConnection.cs = test\shared\MockConnection.cs
test\shared\MockFrameControl.cs = test\shared\MockFrameControl.cs
test\shared\MockSystemClock.cs = test\shared\MockSystemClock.cs
test\shared\SocketInputExtensions.cs = test\shared\SocketInputExtensions.cs
test\shared\TestApplicationErrorLogger.cs = test\shared\TestApplicationErrorLogger.cs
test\shared\TestConnection.cs = test\shared\TestConnection.cs
test\shared\TestKestrelTrace.cs = test\shared\TestKestrelTrace.cs
@ -45,9 +48,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC
test\shared\TestServiceContext.cs = test\shared\TestServiceContext.cs
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "perf", "perf", "{21B17FBB-5A58-42A8-8473-43160509A9FF}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.Performance", "perf\Microsoft.AspNetCore.Server.Kestrel.Performance\Microsoft.AspNetCore.Server.Kestrel.Performance.xproj", "{70567566-524C-4B67-9B59-E5C206D6C2EB}"
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.Server.Kestrel.Performance", "test\Microsoft.AspNetCore.Server.Kestrel.Performance\Microsoft.AspNetCore.Server.Kestrel.Performance.xproj", "{70567566-524C-4B67-9B59-E5C206D6C2EB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -100,6 +101,6 @@ Global
{5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750}
{9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483}
{0EF2ACDF-012F-4472-A13A-4272419E2903} = {D3273454-EA07-41D2-BF0B-FCC3675C2483}
{70567566-524C-4B67-9B59-E5C206D6C2EB} = {21B17FBB-5A58-42A8-8473-43160509A9FF}
{70567566-524C-4B67-9B59-E5C206D6C2EB} = {D3273454-EA07-41D2-BF0B-FCC3675C2483}
EndGlobalSection
EndGlobal

View File

@ -1,3 +1,3 @@
{
"projects": ["src", "perf"]
"projects": [ "src" ]
}

View File

@ -1,38 +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 BenchmarkDotNet.Configs;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Validators;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{
public class DefaultConfig : ManualConfig
{
public DefaultConfig()
{
Add(JitOptimizationsValidator.FailOnError);
Add(new RpsColumn());
Add(Job.Default.
With(Platform.X64).
With(Jit.RyuJit).
With(BenchmarkDotNet.Environments.Runtime.Clr).
With(new GcMode() { Server = true }).
With(RunStrategy.Throughput).
WithLaunchCount(3).
WithWarmupCount(5).
WithTargetCount(10));
Add(Job.Default.
With(BenchmarkDotNet.Environments.Runtime.Core).
With(new GcMode() { Server = true }).
With(RunStrategy.Throughput).
WithLaunchCount(3).
WithWarmupCount(5).
WithTargetCount(10));
}
}
}

View File

@ -1,51 +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;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Server.Kestrel.Internal;
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{
public class MockApplicationErrorLogger : ILogger
{
// Application errors are logged using 13 as the eventId.
private const int ApplicationErrorEventId = 13;
public List<LogMessage> Messages { get; } = new List<LogMessage>();
public int TotalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Error);
public int CriticalErrorsLogged => Messages.Count(message => message.LogLevel == LogLevel.Critical);
public int ApplicationErrorsLogged => Messages.Count(message => message.EventId.Id == ApplicationErrorEventId);
public IDisposable BeginScope<TState>(TState state)
{
return new Disposable(() => { });
}
public bool IsEnabled(LogLevel logLevel)
{
return true;
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
#if false
Console.WriteLine($"Log {logLevel}[{eventId}]: {formatter(state, exception)} {exception?.Message}");
#endif
Messages.Add(new LogMessage { LogLevel = logLevel, EventId = eventId, Exception = exception });
}
public class LogMessage
{
public LogLevel LogLevel { get; set; }
public EventId EventId { get; set; }
public Exception Exception { get; set; }
}
}
}

View File

@ -1,34 +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 Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{
public class MockConnectionControl : IConnectionControl
{
public void CancelTimeout()
{
}
public void End(ProduceEndType endType)
{
}
public void Pause()
{
}
public void ResetTimeout(long milliseconds, TimeoutAction timeoutAction)
{
}
public void Resume()
{
}
public void SetTimeout(long milliseconds, TimeoutAction timeoutAction)
{
}
}
}

View File

@ -1,33 +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 Microsoft.AspNetCore.Server.Kestrel.Internal;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{
public class MockKestrelTrace : KestrelTrace
{
public MockKestrelTrace() : this(new MockApplicationErrorLogger())
{
}
public MockKestrelTrace(MockApplicationErrorLogger testLogger) : base(testLogger)
{
Logger = testLogger;
}
public MockApplicationErrorLogger Logger { get; private set; }
public override void ConnectionRead(string connectionId, int count)
{
}
public override void ConnectionWrite(string connectionId, int count)
{
}
public override void ConnectionWriteCallback(string connectionId, int status)
{
}
}
}

View File

@ -1,37 +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;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{
public static class SocketInputExtensions
{
public static void IncomingData(this SocketInput input, byte[] buffer, int offset, int count)
{
var bufferIndex = offset;
var remaining = count;
while (remaining > 0)
{
var block = input.IncomingStart();
var bytesLeftInBlock = block.Data.Offset + block.Data.Count - block.End;
var bytesToCopy = remaining < bytesLeftInBlock ? remaining : bytesLeftInBlock;
Buffer.BlockCopy(buffer, bufferIndex, block.Array, block.End, bytesToCopy);
bufferIndex += bytesToCopy;
remaining -= bytesToCopy;
input.IncomingComplete(bytesToCopy, null);
}
}
public static void IncomingFin(this SocketInput input)
{
input.IncomingComplete(0, null);
}
}
}

View File

@ -1,29 +0,0 @@
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"BenchmarkDotNet": "0.10.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*"
},
"frameworks": {
"net46": {},
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1-*",
"type": "platform"
}
}
}
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
}
}

View File

@ -7,6 +7,7 @@ using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: NeutralResourcesLanguage("en-us")]
[assembly: AssemblyCompany("Microsoft Corporation.")]

View File

@ -2,7 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Properties;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{

View File

@ -2,10 +2,10 @@
To run a specific benchmark add it as parameter
```
dotnet run -c Release RequestParsing
dotnet run RequestParsing
```
To run all use `All` as parameter
```
dotnet run -c Release All
dotnet run All
```
Using no parameter will list all available benchmarks

View File

@ -8,6 +8,8 @@ using BenchmarkDotNet.Attributes;
using Microsoft.AspNetCore.Server.Kestrel.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers;
using Microsoft.AspNetCore.Testing;
using RequestLineStatus = Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame.RequestLineStatus;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
@ -165,26 +167,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
[Setup]
public void Setup()
{
Trace = new KestrelTrace(new MockKestrelTrace());
Trace = new KestrelTrace(new TestKestrelTrace());
ThreadPool = new LoggingThreadPool(Trace);
MemoryPool = new MemoryPool();
SocketInput = new SocketInput(MemoryPool, ThreadPool);
var serviceContext = new ServiceContext
{
DateHeaderValueManager = new DateHeaderValueManager(),
ServerOptions = new KestrelServerOptions(),
Log = Trace
};
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext)
{
ConnectionControl = new MockConnectionControl(),
SocketInput = SocketInput
};
var connectionContext = new MockConnection(new KestrelServerOptions());
connectionContext.SocketInput = SocketInput;
Frame = new Frame<object>(application: null, context: connectionContext);
}

View File

@ -17,6 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
Add(Job.Default.
With(BenchmarkDotNet.Environments.Runtime.Core).
WithRemoveOutliers(false).
With(new GcMode() { Server = true }).
With(RunStrategy.Throughput).
WithLaunchCount(3).

View File

@ -0,0 +1,3 @@
{
"projects": [ "..\\" ]
}

View File

@ -0,0 +1,42 @@
{
"version": "1.0.0-*",
"dependencies": {
"BenchmarkDotNet": "0.10.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.2.0-*"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1-*",
"type": "platform"
}
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"compile": {
"include": [
"../shared/SocketInputExtensions.cs",
"../shared/TestKestrelTrace.cs",
"../shared/TestApplicationErrorLogger.cs",
"../shared/MockConnection.cs"
]
},
"keyFile": "../../tools/Key.snk",
"copyToOutput": {
"include": "TestResources/testCert.pfx"
}
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"TestResources/testCert.pfx"
]
}
}

View File

@ -18,7 +18,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers
{
ConnectionControl = this;
RequestAbortedSource = new CancellationTokenSource();
ListenerContext = new ListenerContext(new ServiceContext { ServerOptions = options });
ListenerContext = new ListenerContext(new ServiceContext {ServerOptions = options})
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
}
public override void Abort(Exception error = null)