限速 RESTful 消费者
我正在使用速率受限的 Web 服务,该服务每秒仅允许我拨打 5 次电话。我正在使用我的服务器将这些调用代理到 Web 客户端:
Mashery > My Web Server > Client's Browser
我已经优化了此 Web 服务的使用,但有时仍然会超出速率限制。相反,我想做的是在向 Mashery 进行 Web 服务调用之前将客户端的请求保留一秒钟(如果有必要的话,可以保留更长的时间)。
有一些方法可以通过构建一个带有数据库后端的简单队列系统来解决这个问题,但如果某些东西已经存在,我宁愿避免这种情况。是否已经存在某些东西可以限制消费端的速率?
I am consuming a rate-limited web service, which only allows me to make 5 calls per second. I am using my server to proxy these calls to a web client:
Mashery > My Web Server > Client's Browser
I have optimized the usage of this web service, but there are still occasional times when I go over the rate limit. What I would like to do instead is hold the client's request for one second (or longer if warranted) before making the web service call to Mashery.
There are some ways I can solve this by building a simple queue system with a database back-end, but I'd rather avoid that if something already exists. Does something already exist to rate-limit the consuming side of this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了可靠地将请求限制为每秒仅 5 个,我将采用队列/工作线程系统。但在此之前,我只需联系该平台的 API 支持来请求更高的速率限制。当然,如果它是只读方法并且您要提取大量相同的数据并且它符合 API TOS,我也会考虑使用缓存。
To reliably throttle requests to only 5 per second, I would employ a queue/worker system. But before that I would just request a higher rate limit by contacting API support for that platform. Of course, I would also consider using caching if it's a read-only method and you're pulling down a lot of the same data and it's compliant with the API TOS.