I have written an async web api action which will take long time to execute. I want to rate limit the number of outstanding requests for a user to a particular number. I have seen few online articles where they are doing throttling for a period of time. Please guide me about how to throttle number of active requests on user basis.
Asked
Active
Viewed 590 times
2
-
Possible duplicate of [Best way to implement request throttling in ASP.NET MVC?](https://stackoverflow.com/questions/33969/best-way-to-implement-request-throttling-in-asp-net-mvc) – Alex May 23 '18 at 09:57
2 Answers
1
you could build something simple yourself.
request comes in from a user, add an active connection record, in a db table for example.
another request comes in, count existing active connections, add another one if you are below your limit. If not return BadRequest, for example.
A request finishes processing, remove its active connection record so the count goes down.

Andrei Dragotoniu
- 6,155
- 3
- 18
- 32
0
Use existing Nuget throttling extensions, eg: https://github.com/stefanprodan/WebApiThrottle/blob/master/README.md

Sentinel
- 3,582
- 1
- 30
- 44
-
As I mentioned in the original post, the link you have given will help to throttle per second, per minute, per hour per day or even per week. But my requirement is that user shouldn't have more than 10 active concurrent requests to the action method. There is not time constraint here. – user3407500 May 23 '18 at 08:13
-
@user3407500 In that case you should clarify your question, as 'rate limit' means 'limit rate', not 'limit total number of concurrent calls'. The topic is quite broad as you need to decide when in the pipeline you want the limit to take place, and this will affect how you identify the action being called. You also need to clarify what you want to happen to requests that exceed the maximum number, i.e., if you want them queued or discarded etc., and what criteria decides when an action actually ends. – Sentinel May 23 '18 at 10:37