Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit fe93ca3

Browse files
committed
WIP 12
1 parent 769cfb8 commit fe93ca3

8 files changed

+91
-54
lines changed

test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameParsingOverheadBenchmark.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
using System.IO.Pipelines;
66
using System.Text;
77
using BenchmarkDotNet.Attributes;
8+
using Microsoft.AspNetCore.Server.Kestrel.Internal;
89
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
9-
using Microsoft.AspNetCore.Testing;
1010

1111
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
1212
{
@@ -21,11 +21,18 @@ public class FrameParsingOverheadBenchmark
2121
[Setup]
2222
public void Setup()
2323
{
24-
var connectionContext = new MockConnection();
25-
connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => NullParser.Instance;
26-
connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions();
24+
var serviceContext = new ServiceContext
25+
{
26+
HttpParserFactory = _ => NullParser.Instance,
27+
ServerOptions = new KestrelServerOptions()
28+
};
29+
var frameContext = new FrameContext
30+
{
31+
ServiceContext = serviceContext,
32+
ConnectionInformation = new MockConnectionInformation()
33+
};
2734

28-
_frame = new Frame<object>(application: null, context: connectionContext);
35+
_frame = new Frame<object>(application: null, frameContext: frameContext);
2936
}
3037

3138
[Benchmark(Baseline = true, OperationsPerInvoke = InnerLoopCount)]

test/Microsoft.AspNetCore.Server.Kestrel.Performance/FrameWritingBenchmark.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,21 @@ private TestFrame<object> MakeFrame()
9393
{
9494
DateHeaderValueManager = new DateHeaderValueManager(),
9595
ServerOptions = new KestrelServerOptions(),
96-
Log = new MockTrace()
96+
Log = new MockTrace(),
97+
HttpParserFactory = f => new KestrelHttpParser(log: null)
9798
};
98-
var listenerContext = new ListenerContext(serviceContext)
99+
var frameContext = new FrameContext
99100
{
100-
ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000))
101+
ServiceContext = serviceContext,
102+
ConnectionInformation = new MockConnectionInformation()
101103
};
102-
var connectionContext = new ConnectionContext(listenerContext)
104+
105+
var frame = new TestFrame<object>(application: null, context: frameContext)
103106
{
104-
Input = socketInput,
105-
Output = new MockSocketOutput(),
106-
ConnectionControl = new MockConnectionControl()
107+
Input = socketInput.Reader,
108+
Output = new MockSocketOutput()
107109
};
108-
connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new Internal.Http.KestrelHttpParser(log: null);
109110

110-
var frame = new TestFrame<object>(application: null, context: connectionContext);
111111
frame.Reset();
112112
frame.InitializeHeaders();
113113

test/Microsoft.AspNetCore.Server.Kestrel.Performance/Mocks/MockConnectionControl.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Net;
6+
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
7+
using Microsoft.AspNetCore.Server.Kestrel.Transport;
8+
9+
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
10+
{
11+
public class MockConnectionInformation : IConnectionInformation
12+
{
13+
public ListenOptions ListenOptions { get; }
14+
15+
public IPEndPoint RemoteEndPoint { get; }
16+
public IPEndPoint LocalEndPoint { get; }
17+
18+
public ITimeoutControl TimeoutControl { get; } = new MockTimeoutControl();
19+
20+
private class MockTimeoutControl : ITimeoutControl
21+
{
22+
public void CancelTimeout()
23+
{
24+
}
25+
26+
public void ResetTimeout(long milliseconds, TimeoutAction timeoutAction)
27+
{
28+
}
29+
30+
public void SetTimeout(long milliseconds, TimeoutAction timeoutAction)
31+
{
32+
}
33+
}
34+
}
35+
}

test/Microsoft.AspNetCore.Server.Kestrel.Performance/RequestParsingBenchmark.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System;
54
using System.IO.Pipelines;
65
using BenchmarkDotNet.Attributes;
6+
using Microsoft.AspNetCore.Server.Kestrel.Internal;
77
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
8-
using Microsoft.AspNetCore.Testing;
98

109
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
1110
{
@@ -21,11 +20,18 @@ public class RequestParsingBenchmark
2120
[Setup]
2221
public void Setup()
2322
{
24-
var connectionContext = new MockConnection();
25-
connectionContext.ListenerContext.ServiceContext.HttpParserFactory = frame => new KestrelHttpParser(frame.ConnectionContext.ListenerContext.ServiceContext.Log);
26-
connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions();
23+
var serviceContext = new ServiceContext
24+
{
25+
HttpParserFactory = f => new KestrelHttpParser(f.ServiceContext.Log),
26+
ServerOptions = new KestrelServerOptions()
27+
};
28+
var frameContext = new FrameContext
29+
{
30+
ServiceContext = serviceContext,
31+
ConnectionInformation = new MockConnectionInformation()
32+
};
2733

28-
Frame = new Frame<object>(application: null, context: connectionContext);
34+
Frame = new Frame<object>(application: null, frameContext: frameContext);
2935
PipelineFactory = new PipeFactory();
3036
Pipe = PipelineFactory.Create();
3137
}

test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeaderCollectionBenchmark.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using Microsoft.AspNetCore.Http;
77
using Microsoft.AspNetCore.Http.Internal;
88
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
9-
using Microsoft.AspNetCore.Testing;
109
using BenchmarkDotNet.Attributes;
10+
using Microsoft.AspNetCore.Server.Kestrel.Internal;
1111

1212
namespace Microsoft.AspNetCore.Server.Kestrel.Performance
1313
{
@@ -167,10 +167,19 @@ private void Unknown(int count)
167167
[Setup]
168168
public void Setup()
169169
{
170-
var connectionContext = new MockConnection();
171-
connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new KestrelHttpParser(f.ConnectionContext.ListenerContext.ServiceContext.Log);
172-
connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions();
173-
var frame = new Frame<object>(application: null, context: connectionContext);
170+
var serviceContext = new ServiceContext
171+
{
172+
HttpParserFactory = f => new KestrelHttpParser(f.ServiceContext.Log),
173+
ServerOptions = new KestrelServerOptions()
174+
};
175+
var frameContext = new FrameContext
176+
{
177+
ServiceContext = serviceContext,
178+
ConnectionInformation = new MockConnectionInformation()
179+
};
180+
181+
var frame = new Frame<object>(application: null, frameContext: frameContext);
182+
174183
frame.Reset();
175184
frame.InitializeHeaders();
176185
_responseHeadersDirect = (FrameResponseHeaders)frame.ResponseHeaders;

test/Microsoft.AspNetCore.Server.Kestrel.Performance/ResponseHeadersWritingBenchmark.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,22 @@ public void Setup()
120120
{
121121
DateHeaderValueManager = new DateHeaderValueManager(),
122122
ServerOptions = new KestrelServerOptions(),
123-
Log = new MockTrace()
123+
Log = new MockTrace(),
124+
HttpParserFactory = f => new KestrelHttpParser(log: null)
124125
};
125126

126-
var listenerContext = new ListenerContext(serviceContext)
127+
var frameContext = new FrameContext
127128
{
128-
ListenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 5000))
129+
ServiceContext = serviceContext,
130+
ConnectionInformation = new MockConnectionInformation()
129131
};
130132

131-
var connectionContext = new ConnectionContext(listenerContext)
133+
var frame = new TestFrame<object>(application: null, context: frameContext)
132134
{
133-
Input = input,
134-
Output = socketOutput,
135-
ConnectionControl = new MockConnectionControl()
135+
Input = input.Reader,
136+
Output = socketOutput
136137
};
137138

138-
connectionContext.ListenerContext.ServiceContext.HttpParserFactory = f => new KestrelHttpParser(log: null);
139-
connectionContext.ListenerContext.ServiceContext.ServerOptions = new KestrelServerOptions();
140-
141-
var frame = new TestFrame<object>(application: null, context: connectionContext);
142139
frame.Reset();
143140
frame.InitializeHeaders();
144141

test/shared/TestServiceContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public TestServiceContext()
2222
ThreadPool = new LoggingThreadPool(Log);
2323
DateHeaderValueManager = new DateHeaderValueManager(systemClock: new MockSystemClock());
2424
DateHeaderValue = DateHeaderValueManager.GetDateHeaderValues().String;
25-
HttpParserFactory = frame => new KestrelHttpParser(Log);
25+
HttpParserFactory = frame => new KestrelHttpParser(frame.ServiceContext.Log);
2626
ServerOptions = new KestrelServerOptions
2727
{
2828
AddServerHeader = false

0 commit comments

Comments
 (0)