Monday, September 05, 2016

.NET HttpClient for Microservices

ASP.NET Monsters #62: You are probably using HttpClient wrong | ASP.NET Monsters | Channel 9
Apparently .NET TCP stack in some cases can leave socket connection in TIME_WAIT state up to 4 minutes even when the object is disposed. They suggested using static (shared) object(s) (!?) for HTTP communication, since when using micro-services that open many HTTP connections that can leave many TCP sockets open.  I usually use HttpWebRequest that is a lower level API used by HttpClient with more control, but it also may be affected by TCP stack default behavior. This needs some investigation...

You're using HttpClient wrong and it is destabilizing your software | ASP.NET Monsters
Imgur

Imgur


"...number of sockets was averaging around 4000... effectively crushing the available resources on the server, which then caused services to fall over. After implementing the change, the sockets in use dropped to... usually around 100."

WebClient vs HttpClient vs HttpWebRequest - The Geeky Gecko
HttpClient: Microsoft Patterns and Practices documentation

Official documentation (careful with this): Calling a Web API From a .NET Client in ASP.NET Web API 2 (C#) | The ASP.NET Site




No comments: