Skip to content

Commit 83cde61

Browse files
committed
Add option to enable multuple H/3 connections
1 parent 40b0d04 commit 83cde61

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/BenchmarksApps/HttpClientBenchmarks/Clients/HttpClient/ClientOptions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class ClientOptions
1818
public int ConcurrencyPerHttpClient { get; set; }
1919
public int Http11MaxConnectionsPerServer { get; set; }
2020
public bool Http20EnableMultipleConnections { get; set; }
21+
public bool Http30EnableMultipleConnections { get; set; }
2122
public bool UseWinHttpHandler { get; set; }
2223
public bool UseHttpMessageInvoker { get; set; }
2324
public bool CollectRequestTimings { get; set; }
@@ -37,9 +38,9 @@ public override string ToString()
3738
{
3839
return $"Address={Address}; Port={Port}; UseHttps={UseHttps}; Path={Path}; HttpVersion={HttpVersion}; NumberOfHttpClients={NumberOfHttpClients}; " +
3940
$"ConcurrencyPerHttpClient={ConcurrencyPerHttpClient}; Http11MaxConnectionsPerServer={Http11MaxConnectionsPerServer}; " +
40-
$"Http20EnableMultipleConnections={Http20EnableMultipleConnections}; UseWinHttpHandler={UseWinHttpHandler}; " +
41-
$"UseHttpMessageInvoker={UseHttpMessageInvoker}; CollectRequestTimings={CollectRequestTimings}; Scenario={Scenario}; " +
42-
$"ContentSize={ContentSize}; ContentWriteSize={ContentWriteSize}; ContentFlushAfterWrite={ContentFlushAfterWrite}; " +
41+
$"Http20EnableMultipleConnections={Http20EnableMultipleConnections}; Http30EnableMultipleConnections={Http30EnableMultipleConnections}; " +
42+
$"UseWinHttpHandler={UseWinHttpHandler}; UseHttpMessageInvoker={UseHttpMessageInvoker}; CollectRequestTimings={CollectRequestTimings}; " +
43+
$"Scenario={Scenario}; ContentSize={ContentSize}; ContentWriteSize={ContentWriteSize}; ContentFlushAfterWrite={ContentFlushAfterWrite}; " +
4344
$"ContentUnknownLength={ContentUnknownLength}; Headers=[{string.Join(", ", Headers.Select(h => $"\"{h.Name}: {h.Value}\""))}]; " +
4445
$"GeneratedStaticHeadersCount={GeneratedStaticHeadersCount}; GeneratedDynamicHeadersCount={GeneratedDynamicHeadersCount}; " +
4546
$"UseDefaultRequestHeaders={UseDefaultRequestHeaders}; Warmup={Warmup}; Duration={Duration}";

src/BenchmarksApps/HttpClientBenchmarks/Clients/HttpClient/ClientOptionsBinder.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class ClientOptionsBinder : BinderBase<ClientOptions>
1515
public static Option<int> ConcurrencyPerHttpClientOption { get; } = new Option<int>("--concurrencyPerHttpClient", () => 1, "Number of concurrect requests per one HttpClient");
1616
public static Option<int> Http11MaxConnectionsPerServerOption { get; } = new Option<int>("--http11MaxConnectionsPerServer", () => 0, "Max number of HTTP/1.1 connections per server, 0 for unlimited");
1717
public static Option<bool> Http20EnableMultipleConnectionsOption { get; } = new Option<bool>("--http20EnableMultipleConnections", () => true, "Enable multiple HTTP/2.0 connections");
18+
public static Option<bool> Http30EnableMultipleConnectionsOption { get; } = new Option<bool>("--http30EnableMultipleConnections", () => true, "Enable multiple HTTP/3.0 connections");
1819
public static Option<bool> UseWinHttpHandlerOption { get; } = new Option<bool>("--useWinHttpHandler", () => false, "Use WinHttpHandler instead of SocketsHttpHandler");
1920
public static Option<bool> UseHttpMessageInvokerOption { get; } = new Option<bool>("--useHttpMessageInvoker", () => false, "Use HttpMessageInvoker instead of HttpClient");
2021
public static Option<bool> CollectRequestTimingsOption { get; } = new Option<bool>("--collectRequestTimings", () => false, "Collect percentiled metrics of request timings");
@@ -41,6 +42,7 @@ public static void AddOptionsToCommand(RootCommand command)
4142
command.AddOption(ConcurrencyPerHttpClientOption);
4243
command.AddOption(Http11MaxConnectionsPerServerOption);
4344
command.AddOption(Http20EnableMultipleConnectionsOption);
45+
command.AddOption(Http30EnableMultipleConnectionsOption);
4446
command.AddOption(UseWinHttpHandlerOption);
4547
command.AddOption(UseHttpMessageInvokerOption);
4648
command.AddOption(CollectRequestTimingsOption);
@@ -72,6 +74,7 @@ protected override ClientOptions GetBoundValue(BindingContext bindingContext)
7274
ConcurrencyPerHttpClient = parsed.GetValueForOption(ConcurrencyPerHttpClientOption),
7375
Http11MaxConnectionsPerServer = parsed.GetValueForOption(Http11MaxConnectionsPerServerOption),
7476
Http20EnableMultipleConnections = parsed.GetValueForOption(Http20EnableMultipleConnectionsOption),
77+
Http30EnableMultipleConnections = parsed.GetValueForOption(Http30EnableMultipleConnectionsOption),
7578
UseWinHttpHandler = parsed.GetValueForOption(UseWinHttpHandlerOption),
7679
UseHttpMessageInvoker = parsed.GetValueForOption(UseHttpMessageInvokerOption),
7780
CollectRequestTimings = parsed.GetValueForOption(CollectRequestTimingsOption),

src/BenchmarksApps/HttpClientBenchmarks/Clients/HttpClient/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ private static async Task Setup()
129129
SslOptions = new SslClientAuthenticationOptions { RemoteCertificateValidationCallback = delegate { return true; } },
130130
MaxConnectionsPerServer = max11ConnectionsPerServer,
131131
EnableMultipleHttp2Connections = s_options.Http20EnableMultipleConnections,
132+
#if NET9_0_OR_GREATER
133+
EnableMultipleHttp3Connections = s_options.Http30EnableMultipleConnections,
134+
#endif
132135
ConnectTimeout = Timeout.InfiniteTimeSpan,
133136
};
134137
}
@@ -396,7 +399,7 @@ private static void CreateRequestContentData()
396399
}
397400

398401
private static HttpRequestMessage CreateRequest(HttpMethod method, Uri uri) =>
399-
new HttpRequestMessage(method, uri) {
402+
new HttpRequestMessage(method, uri) {
400403
Version = s_options.HttpVersion!,
401404
VersionPolicy = HttpVersionPolicy.RequestVersionExact
402405
};

0 commit comments

Comments
 (0)