Clean up benchmarks (#1487)

- Benchmarks are suffixed with *Benchmarks
- Removed Custom RpsColumn.cs and used Ops/Second column
- Removed params from RequestParsingBenchmark
This commit is contained in:
David Fowler 2017-03-12 22:52:24 -07:00 committed by GitHub
parent 49f09d5a25
commit 5644310811
11 changed files with 37 additions and 65 deletions

View File

@ -0,0 +1,17 @@
using System;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{
public static class ErrorUtilities
{
public static void ThrowInvalidRequestLine()
{
throw new InvalidOperationException("Invalid request line");
}
public static void ThrowInvalidRequestHeaders()
{
throw new InvalidOperationException("Invalid request headers");
}
}
}

View File

@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Testing;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [Config(typeof(CoreConfig))]
public class FrameParsingOverhead public class FrameParsingOverheadBenchmark
{ {
private const int InnerLoopCount = 512; private const int InnerLoopCount = 512;
@ -60,14 +60,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
if (!_frame.TakeStartLine(_buffer, out var consumed, out var examined)) if (!_frame.TakeStartLine(_buffer, out var consumed, out var examined))
{ {
RequestParsing.ThrowInvalidRequestLine(); ErrorUtilities.ThrowInvalidRequestLine();
} }
_frame.InitializeHeaders(); _frame.InitializeHeaders();
if (!_frame.TakeMessageHeaders(_buffer, out consumed, out examined)) if (!_frame.TakeMessageHeaders(_buffer, out consumed, out examined))
{ {
RequestParsing.ThrowInvalidRequestHeaders(); ErrorUtilities.ThrowInvalidRequestHeaders();
} }
} }
@ -77,7 +77,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
if (!_frame.TakeStartLine(_buffer, out var consumed, out var examined)) if (!_frame.TakeStartLine(_buffer, out var consumed, out var examined))
{ {
RequestParsing.ThrowInvalidRequestLine(); ErrorUtilities.ThrowInvalidRequestLine();
} }
} }
@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
if (!_frame.TakeMessageHeaders(_buffer, out var consumed, out var examined)) if (!_frame.TakeMessageHeaders(_buffer, out var consumed, out var examined))
{ {
RequestParsing.ThrowInvalidRequestHeaders(); ErrorUtilities.ThrowInvalidRequestHeaders();
} }
} }

View File

@ -16,13 +16,13 @@ using Moq;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [Config(typeof(CoreConfig))]
public class Writing public class FrameWritingBenchmark
{ {
private readonly TestFrame<object> _frame; private readonly TestFrame<object> _frame;
private readonly TestFrame<object> _frameChunked; private readonly TestFrame<object> _frameChunked;
private readonly byte[] _writeData; private readonly byte[] _writeData;
public Writing() public FrameWritingBenchmark()
{ {
_frame = MakeFrame(); _frame = MakeFrame();
_frameChunked = MakeFrame(); _frameChunked = MakeFrame();

View File

@ -10,9 +10,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [Config(typeof(CoreConfig))]
public class KestrelHttpParser : IHttpRequestLineHandler, IHttpHeadersHandler public class KestrelHttpParserBenchmark : IHttpRequestLineHandler, IHttpHeadersHandler
{ {
private readonly Internal.Http.KestrelHttpParser _parser = new Internal.Http.KestrelHttpParser(log: null); private readonly KestrelHttpParser _parser = new KestrelHttpParser(log: null);
private ReadableBuffer _buffer; private ReadableBuffer _buffer;
@ -55,14 +55,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
if (!_parser.ParseRequestLine(this, _buffer, out var consumed, out var examined)) if (!_parser.ParseRequestLine(this, _buffer, out var consumed, out var examined))
{ {
RequestParsing.ThrowInvalidRequestHeaders(); ErrorUtilities.ThrowInvalidRequestHeaders();
} }
_buffer = _buffer.Slice(consumed, _buffer.End); _buffer = _buffer.Slice(consumed, _buffer.End);
if (!_parser.ParseHeaders(this, _buffer, out consumed, out examined, out var consumedBytes)) if (!_parser.ParseHeaders(this, _buffer, out consumed, out examined, out var consumedBytes))
{ {
RequestParsing.ThrowInvalidRequestHeaders(); ErrorUtilities.ThrowInvalidRequestHeaders();
} }
} }

View File

@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
public class KnownStrings public class KnownStringsBenchmark
{ {
static byte[] _method = Encoding.UTF8.GetBytes("GET "); static byte[] _method = Encoding.UTF8.GetBytes("GET ");
static byte[] _version = Encoding.UTF8.GetBytes("HTTP/1.1\r\n"); static byte[] _version = Encoding.UTF8.GetBytes("HTTP/1.1\r\n");

View File

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

View File

@ -10,11 +10,8 @@ using Microsoft.AspNetCore.Testing;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [Config(typeof(CoreConfig))]
public class RequestParsing public class RequestParsingBenchmark
{ {
[Params(typeof(Internal.Http.KestrelHttpParser))]
public Type ParserType { get; set; }
public IPipe Pipe { get; set; } public IPipe Pipe { get; set; }
public Frame<object> Frame { get; set; } public Frame<object> Frame { get; set; }
@ -25,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
public void Setup() public void Setup()
{ {
var connectionContext = new MockConnection(new KestrelServerOptions()); var connectionContext = new MockConnection(new KestrelServerOptions());
connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => (IHttpParser)Activator.CreateInstance(ParserType, frame.ConnectionContext.ListenerContext.ServiceContext.Log); connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => new KestrelHttpParser(frame.ConnectionContext.ListenerContext.ServiceContext.Log);
Frame = new Frame<object>(application: null, context: connectionContext); Frame = new Frame<object>(application: null, context: connectionContext);
PipelineFactory = new PipeFactory(); PipelineFactory = new PipeFactory();
@ -128,7 +125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
if (!Frame.TakeStartLine(readableBuffer, out var consumed, out var examined)) if (!Frame.TakeStartLine(readableBuffer, out var consumed, out var examined))
{ {
ThrowInvalidRequestLine(); ErrorUtilities.ThrowInvalidRequestLine();
} }
Pipe.Reader.Advance(consumed, examined); Pipe.Reader.Advance(consumed, examined);
@ -139,21 +136,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
if (!Frame.TakeMessageHeaders(readableBuffer, out consumed, out examined)) if (!Frame.TakeMessageHeaders(readableBuffer, out consumed, out examined))
{ {
ThrowInvalidRequestHeaders(); ErrorUtilities.ThrowInvalidRequestHeaders();
} }
Pipe.Reader.Advance(consumed, examined); Pipe.Reader.Advance(consumed, examined);
} }
while (true); while (true);
} }
public static void ThrowInvalidRequestLine()
{
throw new InvalidOperationException("Invalid request line");
}
public static void ThrowInvalidRequestHeaders()
{
throw new InvalidOperationException("Invalid request headers");
}
} }
} }

View File

@ -3,11 +3,9 @@
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using BenchmarkDotNet.Attributes;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))]
public class RequestParsingData public class RequestParsingData
{ {
public const int InnerLoopCount = 512; public const int InnerLoopCount = 512;

View File

@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
[Config(typeof(CoreConfig))] [Config(typeof(CoreConfig))]
public class ResponseHeaders public class ResponseHeadersBenchmark
{ {
private const int InnerLoopCount = 512; private const int InnerLoopCount = 512;

View File

@ -1,31 +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.Linq;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{
public class RpsColumn : IColumn
{
private static int NanosPerSecond = 1000 * 1000 * 1000;
public string GetValue(Summary summary, Benchmark benchmark)
{
var totalNanos = summary.Reports.First(r => r.Benchmark == benchmark)?.ResultStatistics?.Mean ?? 0;
// Make sure we don't divide by zero!!
return Math.Abs(totalNanos) > 0.0 ? (NanosPerSecond / totalNanos).ToString("N2") : "N/A";
}
public bool IsDefault(Summary summary, Benchmark benchmark) => false;
public bool IsAvailable(Summary summary) => true;
public string Id => "RPS-Column";
public string ColumnName => "RPS";
public bool AlwaysShow => true;
public ColumnCategory Category => ColumnCategory.Custom;
public int PriorityInCategory => 1;
}
}

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs; using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers; using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Engines; using BenchmarkDotNet.Engines;
@ -15,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance
{ {
Add(JitOptimizationsValidator.FailOnError); Add(JitOptimizationsValidator.FailOnError);
Add(MemoryDiagnoser.Default); Add(MemoryDiagnoser.Default);
Add(new RpsColumn()); Add(StatisticColumn.OperationsPerSecond);
Add(Job.Default Add(Job.Default
.With(BenchmarkDotNet.Environments.Runtime.Core) .With(BenchmarkDotNet.Environments.Runtime.Core)