Skip to content

Commit

Permalink
adding code for chapter 17 demos
Browse files Browse the repository at this point in the history
  • Loading branch information
cwoodruff committed Dec 19, 2024
1 parent 7a95418 commit 7b5f4fa
Show file tree
Hide file tree
Showing 18 changed files with 263 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Ch17/HTTP3-Perf-Client-Demo/HTTP3-Perf-Client-Demo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>HTTP3_Perf_Demo</RootNamespace>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
31 changes: 31 additions & 0 deletions src/Ch17/HTTP3-Perf-Client-Demo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Diagnostics;
using System.Net;

async Task MeasurePerformance(Version httpVersion, int requestCount)
{
using var client = new HttpClient()
{
DefaultRequestVersion = httpVersion,
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact
};

var tasks = new Task<HttpResponseMessage>[requestCount];
var stopwatch = Stopwatch.StartNew();

for (int i = 0; i < requestCount; i++)
{
tasks[i] = client.GetAsync("https://localhost:5001/process");
}

await Task.WhenAll(tasks);
stopwatch.Stop();

var totalDuration = stopwatch.ElapsedMilliseconds;
Console.WriteLine($"{httpVersion}: Processed {requestCount} requests in {totalDuration}ms");
}

// Measure HTTP/2 performance
await MeasurePerformance(HttpVersion.Version20, 50);

// Measure HTTP/3 performance
await MeasurePerformance(HttpVersion.Version30, 50);
10 changes: 10 additions & 0 deletions src/Ch17/HTTP3-Perf-Server-Demo/HTTP3-Perf-Server-Demo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>HTTP3_Perf_Server_Demo</RootNamespace>
</PropertyGroup>

</Project>
32 changes: 32 additions & 0 deletions src/Ch17/HTTP3-Perf-Server-Demo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Security.Cryptography.X509Certificates;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.AspNetCore.Server.Kestrel.Https;

var builder = WebApplication.CreateBuilder(args);

var cert = CertificateLoader.LoadFromStoreCert("localhost", StoreName.My.ToString(), StoreLocation.CurrentUser, false);

// Configure Kestrel to support HTTP/3, HTTP/2, and HTTP/1.1
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(5001, listenOptions =>
{
listenOptions.UseConnectionLogging();
listenOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
listenOptions.UseHttps(httpsOptions =>
{
httpsOptions.ServerCertificateSelector = (context, host) => cert;
});
});
});

var app = builder.Build();

// Define a simple endpoint to respond with HTTP version and message
app.MapGet("/process", async context =>
{
var protocol = context.Request.Protocol; // Retrieve HTTP protocol version
await context.Response.WriteAsync($"Hello! You are using {protocol}");
});

app.Run();
23 changes: 23 additions & 0 deletions src/Ch17/HTTP3-Perf-Server-Demo/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5000/process",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:5001/process",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
8 changes: 8 additions & 0 deletions src/Ch17/HTTP3-Perf-Server-Demo/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions src/Ch17/HTTP3-Perf-Server-Demo/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
3 changes: 3 additions & 0 deletions src/Ch17/QuicConnection-Client/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// See https://aka.ms/new-console-template for more information

Console.WriteLine("Hello, World!");
12 changes: 12 additions & 0 deletions src/Ch17/QuicConnection-Client/QuicConnection-Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>QuicConnection_Client</RootNamespace>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
3 changes: 3 additions & 0 deletions src/Ch17/QuicConnection-Server/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// See https://aka.ms/new-console-template for more information

Console.WriteLine("Hello, World!");
12 changes: 12 additions & 0 deletions src/Ch17/QuicConnection-Server/QuicConnection-Server.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>QuicConnection_Server</RootNamespace>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
3 changes: 3 additions & 0 deletions src/Ch17/QuicListener-Server/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// See https://aka.ms/new-console-template for more information

Console.WriteLine("Hello, World!");
12 changes: 12 additions & 0 deletions src/Ch17/QuicListener-Server/QuicListener-Server.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>QuicListener_Server</RootNamespace>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
3 changes: 3 additions & 0 deletions src/Ch17/QuicStream-Client/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// See https://aka.ms/new-console-template for more information

Console.WriteLine("Hello, World!");
12 changes: 12 additions & 0 deletions src/Ch17/QuicStream-Client/QuicStream-Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>QuicStream_Client</RootNamespace>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
3 changes: 3 additions & 0 deletions src/Ch17/QuicStream-Server/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// See https://aka.ms/new-console-template for more information

Console.WriteLine("Hello, World!");
12 changes: 12 additions & 0 deletions src/Ch17/QuicStream-Server/QuicStream-Server.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>QuicStream_Server</RootNamespace>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
63 changes: 63 additions & 0 deletions src/Ch17/ch17.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QUICServer", "QUICServer\QU
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QUICConsole", "QUICConsole\QUICConsole.csproj", "{86478148-88AB-4C71-A0DE-42BAB0BF2BB8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuicListener-Server", "QuicListener-Server\QuicListener-Server.csproj", "{2431ABF5-9196-4327-9C5C-19E045F21221}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuicConnection-Server", "QuicConnection-Server\QuicConnection-Server.csproj", "{19A54DCD-B80C-4852-B510-9AF589E796A2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuicConnection-Client", "QuicConnection-Client\QuicConnection-Client.csproj", "{DC39E601-77EE-4AA3-B910-6FD8835F0DE5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuicStream-Server", "QuicStream-Server\QuicStream-Server.csproj", "{35BCBC12-4EE2-411E-8F59-044C2A4B4462}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuicStream-Client", "QuicStream-Client\QuicStream-Client.csproj", "{1D5FCDF5-6C30-46CC-B35F-EE2A4EFD2A27}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTTP3-Perf-Client-Demo", "HTTP3-Perf-Client-Demo\HTTP3-Perf-Client-Demo.csproj", "{4E7E5468-E88A-49A9-B51F-B0B6112FBC39}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTTP3-Perf-Server-Demo", "HTTP3-Perf-Server-Demo\HTTP3-Perf-Server-Demo.csproj", "{76828FDE-FAE9-46AB-B2EA-F44C86D39A96}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HTTP3-Perf-Demo", "HTTP3-Perf-Demo", "{2E4BE413-58A9-40C4-AEA0-3585B8D654D3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "QuicConnection", "QuicConnection", "{5C0DBDCA-7C19-4337-AD0A-870D2A3EC563}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HTTP3-Demo", "HTTP3-Demo", "{8ACAF84B-4D93-407A-9B9F-65467B8B5572}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "QuicListener", "QuicListener", "{040C3298-4FE7-4941-9926-1758E61110E3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "QuicStream", "QuicStream", "{37560D19-40B1-4E32-9805-6DB4A139FA5E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -18,5 +42,44 @@ Global
{86478148-88AB-4C71-A0DE-42BAB0BF2BB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86478148-88AB-4C71-A0DE-42BAB0BF2BB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86478148-88AB-4C71-A0DE-42BAB0BF2BB8}.Release|Any CPU.Build.0 = Release|Any CPU
{2431ABF5-9196-4327-9C5C-19E045F21221}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2431ABF5-9196-4327-9C5C-19E045F21221}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2431ABF5-9196-4327-9C5C-19E045F21221}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2431ABF5-9196-4327-9C5C-19E045F21221}.Release|Any CPU.Build.0 = Release|Any CPU
{19A54DCD-B80C-4852-B510-9AF589E796A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19A54DCD-B80C-4852-B510-9AF589E796A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19A54DCD-B80C-4852-B510-9AF589E796A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19A54DCD-B80C-4852-B510-9AF589E796A2}.Release|Any CPU.Build.0 = Release|Any CPU
{DC39E601-77EE-4AA3-B910-6FD8835F0DE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC39E601-77EE-4AA3-B910-6FD8835F0DE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC39E601-77EE-4AA3-B910-6FD8835F0DE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC39E601-77EE-4AA3-B910-6FD8835F0DE5}.Release|Any CPU.Build.0 = Release|Any CPU
{35BCBC12-4EE2-411E-8F59-044C2A4B4462}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35BCBC12-4EE2-411E-8F59-044C2A4B4462}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35BCBC12-4EE2-411E-8F59-044C2A4B4462}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35BCBC12-4EE2-411E-8F59-044C2A4B4462}.Release|Any CPU.Build.0 = Release|Any CPU
{1D5FCDF5-6C30-46CC-B35F-EE2A4EFD2A27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D5FCDF5-6C30-46CC-B35F-EE2A4EFD2A27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D5FCDF5-6C30-46CC-B35F-EE2A4EFD2A27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D5FCDF5-6C30-46CC-B35F-EE2A4EFD2A27}.Release|Any CPU.Build.0 = Release|Any CPU
{4E7E5468-E88A-49A9-B51F-B0B6112FBC39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E7E5468-E88A-49A9-B51F-B0B6112FBC39}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E7E5468-E88A-49A9-B51F-B0B6112FBC39}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E7E5468-E88A-49A9-B51F-B0B6112FBC39}.Release|Any CPU.Build.0 = Release|Any CPU
{76828FDE-FAE9-46AB-B2EA-F44C86D39A96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76828FDE-FAE9-46AB-B2EA-F44C86D39A96}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76828FDE-FAE9-46AB-B2EA-F44C86D39A96}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76828FDE-FAE9-46AB-B2EA-F44C86D39A96}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4E7E5468-E88A-49A9-B51F-B0B6112FBC39} = {2E4BE413-58A9-40C4-AEA0-3585B8D654D3}
{76828FDE-FAE9-46AB-B2EA-F44C86D39A96} = {2E4BE413-58A9-40C4-AEA0-3585B8D654D3}
{DC39E601-77EE-4AA3-B910-6FD8835F0DE5} = {5C0DBDCA-7C19-4337-AD0A-870D2A3EC563}
{19A54DCD-B80C-4852-B510-9AF589E796A2} = {5C0DBDCA-7C19-4337-AD0A-870D2A3EC563}
{86478148-88AB-4C71-A0DE-42BAB0BF2BB8} = {8ACAF84B-4D93-407A-9B9F-65467B8B5572}
{86A3638C-CB35-4EA5-A21D-DC7A6A17E8F6} = {8ACAF84B-4D93-407A-9B9F-65467B8B5572}
{2431ABF5-9196-4327-9C5C-19E045F21221} = {040C3298-4FE7-4941-9926-1758E61110E3}
{1D5FCDF5-6C30-46CC-B35F-EE2A4EFD2A27} = {37560D19-40B1-4E32-9805-6DB4A139FA5E}
{35BCBC12-4EE2-411E-8F59-044C2A4B4462} = {37560D19-40B1-4E32-9805-6DB4A139FA5E}
EndGlobalSection
EndGlobal

0 comments on commit 7b5f4fa

Please sign in to comment.