开发者

HttpWebRequest stalls when there are multiple keep-alive requests

开发者 https://www.devze.com 2023-01-04 12:32 出处:网络
I am trying to write a load-testing client for a web service server I\'ve wrote. The client interacts with the server using HTTP.

I am trying to write a load-testing client for a web service server I've wrote. The client interacts with the server using HTTP.

The regular clients for my service should use HTTP keep alive (by using HTTP 1.1 and not setting the KeepAlive value to false in HttpWebRequest) so that th开发者_JS百科eir TCP connections stay up for later HTTP requests. Each client does a synchronous request/response at the start to authenticate, then moves on to asynchronous requests.

In my load test I want to have hundreds of simulated clients all sending requests to the same server. But, if I don't set KeepAlive to false in my HttpWebRequests, ALL of the simulated clients apparently try and use the SAME TCP connection, and I get stalls in my load test as they slowly try to share the connection to do their initial synchronous requests. I do not believe that making the first request asynchronous will fix this, I've tried it before and got the same stall in the BeginGetResponse() call (which is supposed to return immediately but doesn't), because it's waiting to get onto the shared connection I think.

Is there some way to make sure each of my "clients" in my load test gets their own TCP connection, which they re-use for future HttpWebRequests?

Someone had a similar question here: HttpWebRequest timeout in 3.5sp1 which they solved by using KeepAlive = false, but that isn't good enough for me because this server is going to have a huge volume and I want to keep the network data transfer to a minimum.


The connection limit might vary depending on the underlying operating system /hosting environment. It can be changed programmatically by setting HttpWebRequest.ServicePoint.ConnectionLimit to a higher value, or in one of .NET's .config files

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号