Parallel requests to the same server with Rest Sharp

3,899 views
Skip to first unread message

John Carlyle-Clarke

unread,
Nov 17, 2011, 3:20:23 AM11/17/11
to rest...@googlegroups.com
I am making a lot of requests to a remote webservice with RestSharp, and I wanted to parallelize them.  I used the Tasks framework to do so.  

What I'm seeing is that when my client is busy and the remote service is a little slow, the time I measure for each request goes up and up.  Yet when I look in Wireshark, the requests take much less time than I'm measuring.

Adding more parallel threads doesn't help - if anything it seems to make things worse.  I switched my code back to the generic Execute() so that I could measure the request separately from the deserialization (just in case) but still the same result.

I don't share any instances of any objects between my threads.

One thing I noticed in Wireshark was that there only seemed to be one TCP connection active per process.  From my reading, I believe what's happening is that connection pooling the HttpWebRequest uses is causing all the threads to share a single underlying connection.  I believe they are contending and blocking on the connection, which can only process one call/response at a time in series.

Is my hypothesis reasonable, and if so, how do I make each thread use its own TCP connection?

Thanks!

John Carlyle-Clarke

unread,
Nov 17, 2011, 5:30:15 AM11/17/11
to rest...@googlegroups.com
I'm now sure my hypothesis is correct, and I've found plenty of documentation to prove it.  In case anyone else hits the same issue, here are some good ideas on how to get around it.

http://stackoverflow.com/questions/866350/how-can-i-programmatically-remove-the-2-connection-limit-in-webclient

Andrew Young

unread,
Nov 17, 2011, 12:48:35 PM11/17/11
to rest...@googlegroups.com
What did you end up doing? Does setting DefaultConnectionLimit help? 
Reply all
Reply to author
Forward
0 new messages