I'm trying to find the correct value for HttpClientHandler.MaxConnectionsPerServer
.
My services conditions:
ASP.NET Core 3.1 - 6.0
HttpClient
.HttpClient
setups via HttpClientFactory
in Startup.cs
:services
.AddHttpClient<IOtherService, OtherService>()
.ConfigureHttpClient(httpClient => httpClient.Timeout = TimeSpan.FromSeconds(3))
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler { MaxConnectionsPerServer = 10 });
Usually, it works pretty well, but sometimes (in a moment of high load) I get many TaskCanceledException
and OtherService
continues to respond as fast as it can. I understand that HttpClientHandler
reaches the limit of MaxConnectionsPerServer
.
My questions:
MaxConnectionsPerServer
? Maybe I should not use MaxConnectionsPerServer
anymore?MaxConnectionsPerServer
?Questions asked by me do not have short answers. The approach described in my question is probably a superficial implementation of the Bulkhead pattern.
My answers:
Is it the correct way of using
MaxConnectionsPerServer
? Maybe I should not useMaxConnectionsPerServer
anymore?
It is the correct way if I want to reduce a load on called service (IOtherService
)
How can I find the correct value for
MaxConnectionsPerServer
?
I have to collect monitoring data and analyze actual cases if I want to find the correct value for MaxConnectionsPerServer
. Also, it can change after changing a load on my service or IOtherService