ASP.NET MVC 3 中的每日调用速率限制?
我看过 Jarrod Dixon 的解决方案(在 ASP.NET MVC 中实现请求限制的最佳方法?)用于实现每秒调用速率限制。我现在正在尝试找出如何为每天 N 次调用构建类似的过滤器。
我正在构建一个开发人员 API,其中免费帐户每天获得约 100 次调用,付费帐户获得更高的速率限制。在 MVC 3 中限制每日调用速率的最佳方法是什么?
I've seen Jarrod Dixon's solution (Best way to implement request throttling in ASP.NET MVC?) for implementing calls-per-second rate limiting. I'm now trying to figure out how to build a similar filter for N-calls-per-day.
I am building a developer API where free accounts get ~100 calls per day and paid accounts get a higher rate limit. What's the best way to do calls-per-day rate limiting in MVC 3?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为内存结构在这里不够用,因为您需要测量很长的持续时间。在这种情况下,IIS 回收会出现问题。因此,我建议记录用户对数据库中资源的访问,并且在过去 24 小时内只允许计数 100。
另一方面,这是我们的漏桶限制器的实现(对于故障相对不重要的短期限制来说更方便)。使用 .NET 4 并发集合可能会改善此实现中的强力锁定:
I don't think that an in-memory structure would suffice here, due to the long duration that you need to measure. IIS recycling would be problematic in this case. As such, I'd recommend recording user access to the resource in the DB and only allowing a count of 100 in the last 24 hours.
On the other hand, here's our implementation of a leaky bucket limiter (which is more handy for short term limiting where failure is relatively unimportant). Using .NET 4 concurrent collections might improve on the somewhat brute-force locking in this implementation: