Skip to content

Commit 35d6d3e

Browse files
authored
feat: docker-based benchmarks comparing OpenSSL perf (#2050)
1 parent c89025e commit 35d6d3e

File tree

6 files changed

+193
-8
lines changed

6 files changed

+193
-8
lines changed

scenarios/tls.benchmarks.yml

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
imports:
2-
- https://raw.githubusercontent.com/dotnet/crank/main/src/Microsoft.Crank.Jobs.Wrk/wrk.yml
32
- https://raw.githubusercontent.com/dotnet/crank/main/src/Microsoft.Crank.Jobs.Bombardier/bombardier.yml
43
- https://raw.githubusercontent.com/dotnet/crank/main/src/Microsoft.Crank.Jobs.HttpClient/httpclient.yml
54
- https://github.com/aspnet/Benchmarks/blob/main/scenarios/aspnet.profiles.yml?raw=true
@@ -42,6 +41,23 @@ jobs:
4241
logRequestDetails: false
4342
arguments: "--urls https://{{serverAddress}}:{{serverPort}} --mTLS {{mTLS}} --certValidationConsoleEnabled {{certValidationConsoleEnabled}} --tlsProtocols {{tlsProtocols}} --statsEnabled {{statsEnabled}} --tlsRenegotiation {{tlsRenegotiation}} --logRequestDetails {{logRequestDetails}}"
4443

44+
dockerLinuxKestrelServer:
45+
sources:
46+
dockerKestrel:
47+
repository: https://github.com/aspnet/benchmarks.git
48+
branchOrCommit: main
49+
dockerFile: dockerKestrel/src/BenchmarksApps/TLS/Kestrel/Dockerfile
50+
dockerImageName: dockerKestrel
51+
dockerContextDirectory: dockerKestrel/src/BenchmarksApps/TLS/Kestrel
52+
port: 8080
53+
readyStateText: Application started.
54+
environmentVariables:
55+
urls: "https://*:8080" # any ip, port 8080
56+
mTLS: false
57+
tlsRenegotiation: false
58+
certValidationConsoleEnabled: false
59+
statsEnabled: false
60+
4561
scenarios:
4662

4763
# HTTP.SYS
@@ -145,4 +161,59 @@ scenarios:
145161
serverScheme: https
146162
certPath: https://raw.githubusercontent.com/aspnet/Benchmarks/refs/heads/main/src/BenchmarksApps/TLS/Kestrel/testCert.pfx
147163
certPwd: testPassword
164+
sslProtocol: tls12
165+
166+
# Kestrel in Docker
167+
tls-handshakes-docker-openssl-332:
168+
application:
169+
job: dockerLinuxKestrelServer
170+
buildArguments:
171+
# openssl version to install
172+
- OPENSSL_VERSION="3.3.2-r4"
173+
# lookup for openssl+branch version here https://pkgs.alpinelinux.org/packages?name=openssl&branch=v3.20&repo=&arch=x86_64
174+
- ALPINE_BRANCH="v3.21"
175+
load:
176+
job: httpclient
177+
variables:
178+
path: /hello-world
179+
serverPort: 8080
180+
presetHeaders: connectionclose
181+
connections: 32
182+
serverScheme: https
183+
sslProtocol: tls12
184+
185+
tls-handshakes-docker-openssl-111:
186+
application:
187+
job: dockerLinuxKestrelServer
188+
buildArguments:
189+
# openssl version to install
190+
- OPENSSL_VERSION="1.1.1w-r1"
191+
# lookup for openssl+branch version here https://pkgs.alpinelinux.org/packages?name=openssl&branch=v3.20&repo=&arch=x86_64
192+
- ALPINE_BRANCH="v3.16"
193+
load:
194+
job: httpclient
195+
variables:
196+
path: /hello-world
197+
serverPort: 8080
198+
presetHeaders: connectionclose
199+
connections: 32
200+
serverScheme: https
201+
sslProtocol: tls12
202+
203+
tls-handshakes-docker-openssl-3015:
204+
application:
205+
job: dockerLinuxKestrelServer
206+
buildArguments:
207+
# openssl version to install
208+
- OPENSSL_VERSION="3.0.15-r1"
209+
# lookup for openssl+branch version here https://pkgs.alpinelinux.org/packages?name=openssl&branch=v3.20&repo=&arch=x86_64
210+
- ALPINE_BRANCH="v3.17"
211+
load:
212+
job: httpclient
213+
variables:
214+
path: /hello-world
215+
serverPort: 8080
216+
presetHeaders: connectionclose
217+
connections: 32
218+
serverScheme: https
148219
sslProtocol: tls12
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
**/.classpath
2+
**/.dockerignore
3+
**/.env
4+
**/.git
5+
**/.gitignore
6+
**/.project
7+
**/.settings
8+
**/.toolstarget
9+
**/.vs
10+
**/.vscode
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md
26+
!**/.gitignore
27+
!.git/HEAD
28+
!.git/config
29+
!.git/packed-refs
30+
!.git/refs/heads/**
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This stage is used when running from VS in fast mode (Default for Debug configuration)
2+
FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine AS base
3+
USER root
4+
WORKDIR /app
5+
EXPOSE 8080
6+
EXPOSE 8081
7+
8+
# Define a build argument for the OpenSSL version
9+
# lookup for openssl+branch version here https://pkgs.alpinelinux.org/packages?name=openssl&branch=v3.20&repo=&arch=x86_64
10+
ARG OPENSSL_VERSION=1.1.1w-r1
11+
ARG ALPINE_BRANCH=v3.16
12+
13+
# Add the specified Alpine branch repository and install OpenSSL
14+
RUN echo "http://dl-cdn.alpinelinux.org/alpine/${ALPINE_BRANCH}/main" >> /etc/apk/repositories && \
15+
apk add --no-cache openssl=${OPENSSL_VERSION} wget perl build-base && \
16+
rm -rf /var/lib/apt/lists/*
17+
18+
# This stage is used to build the service project
19+
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
20+
ARG BUILD_CONFIGURATION=Release
21+
WORKDIR /src
22+
COPY ["Kestrel.csproj", "."]
23+
RUN dotnet restore "./Kestrel.csproj"
24+
COPY . .
25+
WORKDIR "/src/."
26+
RUN dotnet build "./Kestrel.csproj" -c $BUILD_CONFIGURATION -o /app/build
27+
28+
# This stage is used to publish the service project to be copied to the final stage
29+
FROM build AS publish
30+
ARG BUILD_CONFIGURATION=Release
31+
RUN dotnet publish "./Kestrel.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
32+
33+
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
34+
FROM base AS final
35+
WORKDIR /app
36+
COPY --from=publish /app/publish .
37+
38+
ENTRYPOINT [ "dotnet", "Kestrel.dll" ]

src/BenchmarksApps/TLS/Kestrel/Kestrel.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
8+
<DockerfileContext>.</DockerfileContext>
9+
<UserSecretsId>1b89f0d2-44eb-4070-94ec-e963a14ec8b0</UserSecretsId>
710
</PropertyGroup>
811

912
<ItemGroup>
1013
<PackageReference Include="Microsoft.AspNetCore.Authentication.Certificate" Version="9.0.0" />
14+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
1115
</ItemGroup>
1216

1317
<ItemGroup>

src/BenchmarksApps/TLS/Kestrel/Program.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System.Diagnostics;
12
using System.Net;
23
using System.Net.Security;
4+
using System.Runtime.InteropServices;
35
using System.Security.Authentication;
46
using System.Security.Cryptography.X509Certificates;
57
using Microsoft.AspNetCore.Authentication.Certificate;
@@ -9,6 +11,8 @@
911
using Microsoft.AspNetCore.Server.Kestrel.Core;
1012
using Microsoft.AspNetCore.Server.Kestrel.Https;
1113

14+
Console.WriteLine("Starting application...");
15+
1216
var builder = WebApplication.CreateBuilder(args);
1317
builder.Logging.ClearProviders();
1418

@@ -156,6 +160,7 @@ bool AllowAnyCertificateValidationWithLogging(X509Certificate2 certificate, X509
156160
await app.StartAsync();
157161

158162
Console.WriteLine("Application Info:");
163+
LogOpenSSLVersion();
159164
if (mTlsEnabled)
160165
{
161166
Console.WriteLine($"\tmTLS is enabled (client cert is required)");
@@ -219,4 +224,30 @@ static IPEndPoint CreateIPEndPoint(UrlPrefix urlPrefix)
219224
}
220225

221226
return protocols;
227+
}
228+
229+
static void LogOpenSSLVersion()
230+
{
231+
if (!(OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()))
232+
{
233+
return;
234+
}
235+
236+
using var process = new Process()
237+
{
238+
StartInfo =
239+
{
240+
FileName = "/usr/bin/env",
241+
Arguments = "openssl version",
242+
RedirectStandardOutput = true,
243+
RedirectStandardError = true,
244+
UseShellExecute = false,
245+
CreateNoWindow = true
246+
},
247+
};
248+
249+
process.Start();
250+
process.WaitForExit();
251+
var output = process.StandardOutput.ReadToEnd();
252+
Console.WriteLine(output);
222253
}
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
{
2-
"$schema": "http://json.schemastore.org/launchsettings.json",
1+
{
32
"profiles": {
43
"https": {
54
"commandName": "Project",
6-
"dotnetRunMessages": true,
75
"launchBrowser": true,
86
"launchUrl": "hello-world",
9-
"applicationUrl": "https://localhost:5000;http://localhost:5001",
107
"environmentVariables": {
118
"ASPNETCORE_ENVIRONMENT": "Development"
12-
}
9+
},
10+
"dotnetRunMessages": true,
11+
"applicationUrl": "https://localhost:5000;http://localhost:5001"
12+
},
13+
"Container (Dockerfile)": {
14+
"commandName": "Docker",
15+
"launchBrowser": true,
16+
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/hello-world",
17+
"environmentVariables": {
18+
"ASPNETCORE_HTTPS_PORTS": "8080",
19+
"ASPNETCORE_HTTP_PORTS": "8081"
20+
},
21+
"publishAllPorts": true,
22+
"useSSL": true
1323
}
14-
}
15-
}
24+
},
25+
"$schema": "http://json.schemastore.org/launchsettings.json"
26+
}

0 commit comments

Comments
 (0)