diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ErrorUtilities.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ErrorUtilities.cs new file mode 100644 index 0000000000..32ae14d571 --- /dev/null +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ErrorUtilities.cs @@ -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"); + } + } +} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs similarity index 94% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs index aa3bdf84eb..40bf9a6cd0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverhead.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs @@ -11,7 +11,7 @@ using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { [Config(typeof(CoreConfig))] - public class FrameParsingOverhead + public class FrameParsingOverheadBenchmark { 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)) { - RequestParsing.ThrowInvalidRequestLine(); + ErrorUtilities.ThrowInvalidRequestLine(); } _frame.InitializeHeaders(); 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)) { - RequestParsing.ThrowInvalidRequestLine(); + ErrorUtilities.ThrowInvalidRequestLine(); } } @@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance if (!_frame.TakeMessageHeaders(_buffer, out var consumed, out var examined)) { - RequestParsing.ThrowInvalidRequestHeaders(); + ErrorUtilities.ThrowInvalidRequestHeaders(); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs similarity index 97% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs index 9e641715e6..d632e337cd 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/Writing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs @@ -16,13 +16,13 @@ using Moq; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { [Config(typeof(CoreConfig))] - public class Writing + public class FrameWritingBenchmark { private readonly TestFrame _frame; private readonly TestFrame _frameChunked; private readonly byte[] _writeData; - public Writing() + public FrameWritingBenchmark() { _frame = MakeFrame(); _frameChunked = MakeFrame(); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs similarity index 87% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs index a4da66cbe6..0a06b448d0 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParser.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KestrelHttpParserBenchmark.cs @@ -10,9 +10,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { [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; @@ -55,14 +55,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { if (!_parser.ParseRequestLine(this, _buffer, out var consumed, out var examined)) { - RequestParsing.ThrowInvalidRequestHeaders(); + ErrorUtilities.ThrowInvalidRequestHeaders(); } _buffer = _buffer.Slice(consumed, _buffer.End); if (!_parser.ParseHeaders(this, _buffer, out consumed, out examined, out var consumedBytes)) { - RequestParsing.ThrowInvalidRequestHeaders(); + ErrorUtilities.ThrowInvalidRequestHeaders(); } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs similarity index 98% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs index f5fd841f90..2bdc526f9e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStrings.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/KnownStringsBenchmark.cs @@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - public class KnownStrings + public class KnownStringsBenchmark { static byte[] _method = Encoding.UTF8.GetBytes("GET "); static byte[] _version = Encoding.UTF8.GetBytes("HTTP/1.1\r\n"); diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughput.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs similarity index 98% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughput.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs index dc99101261..abdd7ab8b7 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughput.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/PipeThroughputBenchmark.cs @@ -10,7 +10,7 @@ using BenchmarkDotNet.Attributes; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { [Config(typeof(CoreConfig))] - public class PipeThroughput + public class PipeThroughputBenchmark { private const int _writeLenght = 57; private const int InnerLoopCount = 512; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs similarity index 87% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs index ccaf08ba57..0b2e0ee914 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsing.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs @@ -10,11 +10,8 @@ using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { [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 Frame Frame { get; set; } @@ -25,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance public void Setup() { 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(application: null, context: connectionContext); PipelineFactory = new PipeFactory(); @@ -128,7 +125,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance if (!Frame.TakeStartLine(readableBuffer, out var consumed, out var examined)) { - ThrowInvalidRequestLine(); + ErrorUtilities.ThrowInvalidRequestLine(); } Pipe.Reader.Advance(consumed, examined); @@ -139,21 +136,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance if (!Frame.TakeMessageHeaders(readableBuffer, out consumed, out examined)) { - ThrowInvalidRequestHeaders(); + ErrorUtilities.ThrowInvalidRequestHeaders(); } Pipe.Reader.Advance(consumed, examined); } while (true); } - - public static void ThrowInvalidRequestLine() - { - throw new InvalidOperationException("Invalid request line"); - } - - public static void ThrowInvalidRequestHeaders() - { - throw new InvalidOperationException("Invalid request headers"); - } } } diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs index 45b585a2d0..5c496960bb 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingData.cs @@ -3,11 +3,9 @@ using System.Linq; using System.Text; -using BenchmarkDotNet.Attributes; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { - [Config(typeof(CoreConfig))] public class RequestParsingData { public const int InnerLoopCount = 512; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaders.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersBenchmark.cs similarity index 99% rename from test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaders.cs rename to test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersBenchmark.cs index a8dcf79468..b576735168 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaders.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersBenchmark.cs @@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Performance { [Config(typeof(CoreConfig))] - public class ResponseHeaders + public class ResponseHeadersBenchmark { private const int InnerLoopCount = 512; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs deleted file mode 100644 index 9727e7110d..0000000000 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/columns/RpsColumn.cs +++ /dev/null @@ -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; - } -} diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs index 01f4c02318..49897ae207 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.Performance/configs/CoreConfig.cs @@ -1,6 +1,7 @@ // 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.Columns; using BenchmarkDotNet.Configs; using BenchmarkDotNet.Diagnosers; using BenchmarkDotNet.Engines; @@ -15,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Performance { Add(JitOptimizationsValidator.FailOnError); Add(MemoryDiagnoser.Default); - Add(new RpsColumn()); + Add(StatisticColumn.OperationsPerSecond); Add(Job.Default .With(BenchmarkDotNet.Environments.Runtime.Core)