1

I am working on old project, and I found weird problem, which I am not able to explain. It is about communication from my client app to server app. Server is running under IIS app pool and client is running localy (console app).

In Client app (sender), I am using parallel foreach. I clearly see, that there are 16 threads created at the beggining, each thread should be sending its request to IIS, however on the server side I see that there are only two requests processed at the time. Which coresponds to my log file, where is visible that first two requests are processed within one second, and other requests are taking double, triple or more time (they are waiting somewhere to get to the server). I have checked it in logs on server app. I also used performance monitor on server side, where I checked HTTP service request queue ArrivalRate (which is always two per second - one request takes about one second) and CurrentQueueSize which is always zero. On client side, I have tried to trace System.Net library, and from the log there is clearly visible, that it is not sending all the requests at once, but only two at the time.

I observed similar behavior on my test app. I prepared one project for IIS - web application with WebService.asmx and second console app, where I added Web Reference (it is old, I know, but it is this way implemented in my old app). When it is running localy, it utilize all 16 threads, so no request is waiting. But when it is published into the IIS on Server, it is processing at maximum of 10 threads. Again, when I try to run the requests on Server (from web browser), it runs easily in 16 threads.

Therefore I believe, there is some kind of limitation in System.Net library. Because my code is using 16 threads, and the server is getting only two requests at the time. (In my test app server gets about 10 requests at time.)

The question is: Is there some kind of setting for this library? Or does it behave this ways for some reason? Is this behavior documented somewhere?

All is running on .NET Framework 4.0. Client app is using Web Reference. All is done synchronously (except that parallel foreach).

  • Related: [Maximum concurrent requests for WebClient, HttpWebRequest, and HttpClient](https://stackoverflow.com/questions/39516598/maximum-concurrent-requests-for-webclient-httpwebrequest-and-httpclient) – Theodor Zoulias Aug 02 '22 at 17:09
  • If you just check the number of threads in a process you will see all the threads in the threadpool. Not all of these threads will be used by Parallel.For, rather, it will use some heuristics to try to optimize throughput, i.e. use as many threads as you have CPU cores. Besides, if you are making web requests you should Preferably move to use Async IO. – JonasH Aug 02 '22 at 18:20
  • 1
    @TheodorZoulias Thanks, that is exactly what I was looking for, but was unable to google it. – Aleš Jaterka Aug 03 '22 at 07:40

0 Answers0