限制由Rails应用程序生成的出站API调用 [英] Throttling outbound API calls generated by a Rails app

查看:87
本文介绍了限制由Rails应用程序生成的出站API调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是专业的Web开发人员,但是我喜欢把网站当作一种爱好.最近,我一直在将Rails应用程序开发为一个项目,以帮助我学习框架.我的玩具应用程序的目标是通过其API从其他服务中收集数据,并让我可以使用搜索功能进行查询.

I am not a professional web developer, but I like to wrench on websites as a hobby. Recently, I have been playing with developing a Rails app as a project to help me learn the framework. The goal of my toy app is to harvest data from another service through their API and make it available for me to query using a search function.

但是,我要从中提取数据的服务对每分钟可能执行的API调用的数量施加了速率限制.我计划让我的应用运行每日更新,这可能会产生大量的API调用,这些调用远远超出了外部服务所提供的限制.我希望尊重外部站点的性能,因此希望限制我的应用执行呼叫的速度.

However, the service I want to pull data from imposes a rate limit on the number of API calls that may be executed per minute. I plan on having my app run a daily update which may generate a burst of API calls that far exceeds the limit provided by the external service. I wish to respect the performance of the external site and so would like to throttle the rate at which my app executes the calls.

我已经做了一些搜索,并且发现了大量的教程材料和预建库涵盖了对Web应用程序的 inbound API调用的限制,我几乎找不到控制的讨论.呼出流量.

I have done a little bit of searching and the overwhelming amount of tutorial material and pre-built libraries I have found cover throttling inbound API calls to a web app and I can find little discussion of controlling the flow of outbound calls.

作为业余Web开发人员和Rails新手,我很可能在错误的位置执行了错误的搜索.因此,我的问题是:

Being both an amateur web developer and a rails newbie, it is entirely possible that I have been executing the wrong searches in the wrong places. Therefore my questions are:

  • 那里是否有一个不错的网站,汇总了有关节流出站API请求的材料的Rails教程?

  • Is there a nice website out there aggregating Rails tutorials that has material related to throttling outbound API requests?

是否有任何红宝石或其他库可以帮助我限制请求?

Are there any ruby gems or other libraries that would help me throttle the requests?

对于如何使用基于队列的工作程序(如DelayedJob或Resque)来管理API调用,我有一些想法,但我宁愿度过周末构建网站的其余部分好的预先构建好的解决方案.

I have some ideas of how I might go about writing a throttling system using a queue-based worker like DelayedJob or Resque to manage the API calls, but I would rather spend my weekends building the rest of the site if there is a good pre-built solution out there already.

推荐答案

没有人谈论出站限制的原因是它通常很琐碎,因为可以控制它.控制带宽可能会比较困难,但是控制请求数量呢?

The reason nobody talk about outbound throttling is that it's usually pretty trivial, since you control it. Controlling bandwidth can be a bit harder, but controlling number of request ?

ri Kernel#sleep

因此,如果每分钟允许10次api调用,则每次调用后只需休眠(6)

So, if you're allowed 10 api calls per min you just sleep(6) after each call

这篇关于限制由Rails应用程序生成的出站API调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆