基于Memcache的限速算法? (令牌桶?)
我正在寻找一种有效的方法来限制从 Google App Engine 到第三方服务的请求速率。第三方服务速率限制每个帐户的请求,而在 Google App Engine 方面,大部分工作是在任务内部执行的。令牌桶在这里是一个很好的通用算法。
问:可以使用什么方法来有效地对每个帐户而不是每个服务的请求进行速率限制?
这不应该涉及在 GAE 任务队列上设置速率,因为每个帐户的请求数量和服务的帐户数量会有很大差异。出于性能原因,我对基于内存缓存(incr/decr?)的想法最感兴趣!
我认为这可以归结为基于memcache的令牌桶?
想法?
I'm looking for an efficient approach to rate-limiting request from Google App Engine to a third party service. The third party service rate limits requests on a per-account basis, and on the Google App Engine side, most of the work is carried out inside tasks. Token buckets are a great general algorithm here.
Q: what approach can be used to efficiently rate-limit requests on a per-account rather than per-service basis?
This should not involve setting up rates on GAE task queues as the number of requests per account and the number of accounts serviced will vary greatly. For performance reason I'm most interested in memcache-based (incr/decr?) ideas!
I think this boils down to memcache-based token bucket?
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不久前将此项目保留为书签:http://code.google.com/ p/gaedjango-ratelimitcache/
并不是您具体问题的真正答案,但也许它可以帮助您入门。
I kept this project as a bookmark a while ago : http://code.google.com/p/gaedjango-ratelimitcache/
Not really an answer to your specific question but maybe it could help you get started.
我知道这是一个老问题,但它是热门搜索结果,我认为其他人可能会找到我制作的有用的替代方案。与上面的解决方案相比,它更精细(精确到第二个)、更简单(只有一个函数)和更高性能(只有一个内存缓存查找):
I know this is an old question, but it's a top search result and I thought others might find an alternative I made useful. It's a bit more granular (down to the second), simple (only a single function), and performant (only one memcache lookup) than the solution above:
以下是我在 GAE 上使用 memcache 实现令牌桶的方法:
编辑:对此进行(另一个)尝试。
这部分借自 https://github.com/simonw/ratelimitcache/blob /master/ratelimitcache.py
以下是使用示例:
Here is how I implemented token bucket with memcache on GAE:
Edit: taking (another) stab at this.
This is borrowed in part from https://github.com/simonw/ratelimitcache/blob/master/ratelimitcache.py
Here are usage examples: