How to limit number of HttpWebRequest per second towards a webserver?

前端 未结 3 1458
日久生厌
日久生厌 2021-02-09 05:37

I need to implement a throttling mechanism (requests per second) when using HttpWebRequest for making parallel requests towards one application server. My C# app must issue no m

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-09 06:16

    My original post discussed how to add a throttling mechanism to WCF via client behavior extensions, but then was pointed out that I misread the question (doh!).

    Overall the approach can be to check with a class that determines if we are violating the rate limit or not. There's already been a lot of discussion around how to check for rate violations.

    Throttling method calls to M requests in N seconds

    If you are violating the rate limit, then sleep for a fix interval and check again. If not, then go ahead and make the HttpWebRequest call.

提交回复
热议问题