I collect JSON data from several remote servers simultaneously via HTTP using the WCF service both on the client endpoints and on the server. I notice that for every consecutive request that runs asynchronously, the time that an HTTP request accepts usually increases, even if the amount of data does not necessarily increase. In other words, if I run 12 streaming stream streams (using Func <>. BeginInvoke), each request after it is synchronized is displayed in my logs as such:
:HttpRequest invoked. Elapsed: 325ms :HttpRequest invoked. Elapsed: 27437ms :HttpRequest invoked. Elapsed: 28642ms :HttpRequest invoked. Elapsed: 28496ms :HttpRequest invoked. Elapsed: 32544ms :HttpRequest invoked. Elapsed: 38073ms :HttpRequest invoked. Elapsed: 41231ms :HttpRequest invoked. Elapsed: 47914ms :HttpRequest invoked. Elapsed: 45570ms :HttpRequest invoked. Elapsed: 61602ms :HttpRequest invoked. Elapsed: 53567ms :HttpRequest invoked. Elapsed: 79081ms
The process is quite simple. I simply run each request in a loop and then call .WaitAll () for all operations before using the consolidated data.
Http requests seem to take longer than with a small amount of data. In fact, the difference between small and large amounts of data seems to be minimal overall. Could this be a bottleneck due to concurrent HTTP requests that need to share bandwidth, or is there a streaming / context switching problem? Just look to be directed in the right direction.
EDIT . Just for clarity, I performed the same process synchronously and here are the results:
:HttpRequest invoked. Elapsed: 20627ms :HttpRequest invoked. Elapsed: 16288ms :HttpRequest invoked. Elapsed: 2273ms :HttpRequest invoked. Elapsed: 4578ms :HttpRequest invoked. Elapsed: 1920ms :HttpRequest invoked. Elapsed: 564ms :HttpRequest invoked. Elapsed: 1210ms :HttpRequest invoked. Elapsed: 274ms :HttpRequest invoked. Elapsed: 145ms :HttpRequest invoked. Elapsed: 21447ms :HttpRequest invoked. Elapsed: 27001ms :HttpRequest invoked. Elapsed: 1957ms
The total time (due to its synchronism) has increased, however you can clearly see that each individual request is usually faster. Unfortunately, I do not know how to isolate the problem, but I assume that there is a problem with the bandwidth between threads.
So I have a simpler question:
1) If I use thread-thread-thread, this will improve
2) Should I group operations into only several threads, and not every request that has its own?
3) Is this a standard problem while downloading Http data?