0

I have two C# asp.net applications running on IIS: The main application creates up to 80 threads where each of them will establish an http connection to a certrain endpoint (all the same endpoint (LAN)) at a frequency of roughly 3 seconds. That endpoint is beeing hosted on localhost (e.g localhost:4510). This endpoint is the second application which represents the "driver" that will ultimately establish a connection to a device within LAN. So it's totally possible to have 80 threads trying to make a request to driver/device at the same time.

Over time the app seems to have issues with anything involving httpclients. RavenDB, Elasticsearch and also the 80 threads. I read a few things about ServicePointManager class; especially DefaultConnectionLimit and MaxServicePoints and how the influence http througput. I only have basic understanding of the underlying mechanism so I'd like to ask if I should focus on a specific subject or what I would want to check to may improve on http throughput.

Update: With current configuration CPU load is low and memory consumption also. Following code shows how the 80 httpclients which connect to the driver on localhost:4510:

var driverBaseAddressSp= ServicePointManager.FindServicePoint(driverBaseAddress);                               Debug.WriteLine(driverBaseAddressSp.ConnectionLimit);
Debug.WriteLine(driverBaseAddressSp.MaxIdleTime);
var connectionUriSp = ServicePointManager.FindServicePoint(connectionUri);
Debug.WriteLine(connectionUriSp.ConnectionLimit);
Debug.WriteLine(connectionUriSp.MaxIdleTime);
return new HttpClient { BaseAddress = driverBaseAddress }; 

ConnectionLimit shows Int.Max when debugging but I cannot find any configuration in the solution?

yBother
  • 648
  • 6
  • 25
  • There may be other applications/servers that are running at a higher priority that are locking out the http. I can't tell. but I would check Control Panel and check memory usage. You may be exceeding the amount of memory in the machine and then using swap space (a virtual disk) which will slow down the app. – jdweng Dec 18 '19 at 11:36
  • I updated the description – yBother Dec 18 '19 at 12:41
  • It is bad practice to spawn threads in asp.net, it messes with the highly tuned thread management. HTTP calls are naturally I/O bound so ideally you would convert all of these to `async` and you would need no additional threads. – Crowcoder Dec 18 '19 at 12:49
  • Additionally you should [reuse HttpClient](https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/) – Crowcoder Dec 18 '19 at 12:52
  • Well I am aware of the fact that it would be better not to use Task.Run but I cannot believe that this is the actual problem since we do not have any CPU/Memory issues. Also I am aware of the fact, that reusing of httpclient would be better. In fact I currently refactoring.. – yBother Dec 18 '19 at 12:59
  • Where would I change ServicePointManager config in the first place? In driver or main app or even both? – yBother Dec 19 '19 at 10:14

0 Answers0