HttpClient: Only one usage of each socket address (protocol/network address/port) is normally permitted

前端 未结 4 657
死守一世寂寞
死守一世寂寞 2021-01-04 09:06
using (var client = new HttpClient())
{
 client.BaseAddress = new Uri(Url);
 client.DefaultRequestHeaders.Accept.Clear();
 client.DefaultRequestHeaders.Accept.Add(ne         


        
4条回答
  •  庸人自扰
    2021-01-04 09:51

    I hit the same in my load generator tool which tried to send 200 requests/sec to one server.

    I moved from new HttpClient instance per request to a singleton and it did address it.

    One note - initially I hit 2 requests/sec bottleneck but setting DefaultConnectionLimit to 500 solved it:

    ServicePointManager.DefaultConnectionLimit = 500;
    

提交回复
热议问题