HttpClient does not work under heavy load

I am having serious problems with .NET HttpClientunder heavy load. I created a GitHub repository to demonstrate the problem. I would really appreciate any help. Yes, I use only one HttpClientfor every authority. Same issue with http and https. Not a server side issue, as the server maintains responsiveness all the time.

https://github.com/erikbra/HttpClientProblems/issues/1

Usually the following error occurs. System.NetThe trace log says it is calling ::Abortin a connection. But it’s very difficult to get additional information.

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: The connection with the server was terminated abnormally
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.Tasks.RendezvousAwaitable`1.GetResult()
   at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()
   --- End of inner exception stack trace ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at UnitTests.Call_Api.<CallApi>d__22.MoveNext() in C:\Users\ErikBrandstadmoen\Source\Repos\HttpClientProblems\UnitTests.NetCore\Call_Api.cs:line 204
   --- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at UnitTests.Call_Api.<Measure>d__23.MoveNext() in C:\Users\ErikBrandstadmoen\Source\Repos\HttpClientProblems\UnitTests.NetCore\Call_Api.cs:line 219

[UPDATE]

, , . , , ? , . ?

, , . ServicePointManager.DefaultConnectionLimit 2 4 ? ? , , 128 1000. - . , ? TaskCanceledException, . ?

+4
1

github, . ServicePoint , async.

: https://docs.microsoft.com/en-us/dotnet/framework/network-programming/managing-connections

, , , MaxDegreeOfParalelism , .

[]

, System.Net.Http.WinHttpHandler:

https://msdn.microsoft.com/en-us/library/system.net.http.winhttphandler(v=vs.105).aspx

HttpClient, - :

var httpMessageHandler = new System.Net.Http.WinHttpHandler();
//here you set different handler options (see docs link above)
var httpClient = new HttpClient(httpMessageHandler);
+2

Source: https://habr.com/ru/post/1686485/


All Articles