Simultaneous loading of JSON data from remote services

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?

+6
source share
3 answers

The best answer to this question that I eventually came up with came from this link:

http://blogs.msdn.com/b/wenlong/archive/2010/02/11/why-are-wcf-responses-slow-and-setminthreads-does-not-work.aspx

What applies if you repeatedly call the same processing method.

Thanks to setting ThreadPool.SetMinThreads () on the client and server, I was able to get improved results.

However, there are still many unresolved issues with WCF and HTTP transfer that I still have not received.

0
source

According to this question, there is a parameter that determines how many concurrent HTTP requests can be made. In addition, you should use the BeginGetResponse method for HttpWebRequest to load at the same time, since it is cheaper than creating threads. Look here for an example.

+2
source

May be related to the concurrency mode of your service. Check out http://msdn.microsoft.com/en-us/library/system.servicemodel.concurrencymode.aspx and make sure that the service is not single.

+2
source

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


All Articles