HttpWebRequest Port Exhaustion

前端 未结 3 878
梦毁少年i
梦毁少年i 2021-02-09 22:39

We are using a Windows Service to make very frequent HTTP calls to an internal REST service (20-40 calls per second), but notice a long delay in getting responses after the serv

3条回答
  •  情话喂你
    2021-02-09 23:22

    There is a limit in the number of simultaneous outgoing HTTP connections. You can control this by using the System.Net.ServicePointManager.DefaultConnectionLimit static property before creating the HttpWebRequest objects

    It might be worthwhile setting this to a higher value than the default which I believe is 2.

    If this does not help then you can also increase the default ThreadPool size to allow you to create more requests quicker. The thread pool only ramps up its number of threads gradually - a new thread per every half second, IIRC

提交回复
热议问题