How do I prevent Socket/Port Exhaustion?

前端 未结 5 1964
被撕碎了的回忆
被撕碎了的回忆 2020-12-09 04:56

I am attempting to performance test a website by hitting it with requests across multiple threads. Each thread executes n times. (in a for loop)

However, I

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 05:19

    You don't need to mess around with TIME_WAIT to accomplish what you want.

    The problem is that you are disposing the WebClient every time you call Execute(). When you do that, you close the socket connection with the server and the TCP port keeps busy for the TIME_WAIT period.

    A better approach is to create the WebClient in the constructor of your HttpGetTest class and reuse the same object throughout the test.

    WebClient uses keep alive by default and will reuse the same connection for all its requests so in your case there will be only 100 opened connections for this.

提交回复
热议问题