Skip to content

Commit 1e143c7

Browse files
authored
Add Hostable Web Core based inprocess test server (#853)
1 parent 23cb0c9 commit 1e143c7

29 files changed

+1326
-767
lines changed

benchmarks/IIS.Performance/IIS.Performance.csproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<!-- Using shorter assembly name instead of Microsoft.AspNetCore.Server.Kestrel.Performance because https://github.com/dotnet/BenchmarkDotNet/issues/498 -->
@@ -15,13 +15,21 @@
1515
<Content Include="..\..\test\IISIntegration.FunctionalTests\AppHostConfig\*.config" CopyToOutputDirectory="PreserveNewest" />
1616
</ItemGroup>
1717

18+
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
19+
<None Include="$(MSBuildThisFileDirectory)..\..\src\AspNetCoreModuleV2\InProcessRequestHandler\bin\$(Configuration)\x64\aspnetcorev2_inprocess.dll" CopyToOutputDirectory="PreserveNewest" Visible="true" Link="%(FileName)%(Extension)" />
20+
<None Include="$(MSBuildThisFileDirectory)..\..\src\AspNetCoreModuleV2\InProcessRequestHandler\bin\$(Configuration)\x64\aspnetcorev2_inprocess.pdb" CopyToOutputDirectory="PreserveNewest" Visible="true" Link="%(FileName)%(Extension)" />
21+
<None Include="$(MSBuildThisFileDirectory)..\..\src\AspNetCoreModuleV2\AspNetCore\bin\$(Configuration)\x64\aspnetcorev2.dll" CopyToOutputDirectory="PreserveNewest" Visible="true" Link="%(FileName)%(Extension)" />
22+
<None Include="$(MSBuildThisFileDirectory)..\..\src\AspNetCoreModuleV2\AspNetCore\bin\$(Configuration)\x64\aspnetcorev2.pdb" CopyToOutputDirectory="PreserveNewest" Visible="true" Link="%(FileName)%(Extension)" />
23+
</ItemGroup>
24+
1825
<ItemGroup>
1926
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Server.IISIntegration\Microsoft.AspNetCore.Server.IISIntegration.csproj" />
27+
<ProjectReference Include="..\..\test\IISIntegration.FunctionalTests\IISIntegration.FunctionalTests.csproj" />
2028
<ProjectReference Include="..\..\test\WebSites\**\*.csproj">
2129
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
2230
</ProjectReference>
2331
</ItemGroup>
24-
32+
2533
<ItemGroup>
2634
<PackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNetPackageVersion)" />
2735
<PackageReference Include="Microsoft.AspNetCore.BenchmarkRunner.Sources" PrivateAssets="All" Version="$(MicrosoftAspNetCoreBenchmarkRunnerSourcesPackageVersion)" />
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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.Http;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using BenchmarkDotNet.Attributes;
9+
using IISIntegration.FunctionalTests.Utilities;
10+
using Microsoft.AspNetCore.Builder;
11+
using Microsoft.AspNetCore.Http;
12+
using Microsoft.Extensions.Logging;
13+
14+
namespace Microsoft.AspNetCore.Server.IIS.Performance
15+
{
16+
[AspNetCoreBenchmark]
17+
public class PlaintextBenchmark
18+
{
19+
private TestServer _server;
20+
21+
private HttpClient _client;
22+
23+
[GlobalSetup]
24+
public void Setup()
25+
{
26+
_server = TestServer.Create(builder => builder.UseMiddleware<PlaintextMiddleware>(), new LoggerFactory()).GetAwaiter().GetResult();
27+
// Recreate client, TestServer.Client has additional logging that can hurt performance
28+
_client = new HttpClient()
29+
{
30+
BaseAddress = _server.HttpClient.BaseAddress
31+
};
32+
}
33+
34+
[Benchmark]
35+
public async Task Plaintext()
36+
{
37+
await _client.GetAsync("/plaintext");
38+
}
39+
40+
// Copied from https://github.com/aspnet/benchmarks/blob/dev/src/Benchmarks/Middleware/PlaintextMiddleware.cs
41+
public class PlaintextMiddleware
42+
{
43+
private static readonly PathString _path = new PathString("/plaintext");
44+
private static readonly byte[] _helloWorldPayload = Encoding.UTF8.GetBytes("Hello, World!");
45+
46+
private readonly RequestDelegate _next;
47+
48+
public PlaintextMiddleware(RequestDelegate next)
49+
{
50+
_next = next;
51+
}
52+
53+
public Task Invoke(HttpContext httpContext)
54+
{
55+
if (httpContext.Request.Path.StartsWithSegments(_path, StringComparison.Ordinal))
56+
{
57+
return WriteResponse(httpContext.Response);
58+
}
59+
60+
return _next(httpContext);
61+
}
62+
63+
public static Task WriteResponse(HttpResponse response)
64+
{
65+
var payloadLength = _helloWorldPayload.Length;
66+
response.StatusCode = 200;
67+
response.ContentType = "text/plain";
68+
response.ContentLength = payloadLength;
69+
return response.Body.WriteAsync(_helloWorldPayload, 0, payloadLength);
70+
}
71+
}
72+
}
73+
}

benchmarks/IIS.Performance/StartupTimeBenchmark.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Net.Http;
66
using System.Threading.Tasks;
77
using BenchmarkDotNet.Attributes;
8-
using BenchmarkDotNet.Running;
98
using Microsoft.AspNetCore.Server.IntegrationTesting;
109
using Microsoft.AspNetCore.Testing;
1110
using Microsoft.Extensions.Logging.Abstractions;

0 commit comments

Comments
 (0)