TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How to be below API rate limits from multiple servers

28 点作者 ad93611超过 11 年前

4 条评论

akerl_超过 11 年前
Reading the title, I was expecting to see a somewhat shady article on using multiple servers to dodge API rate limits.<p>Instead, they&#x27;ve got a pretty snazzy writeup of how to effectively keep your distributed processes working together properly. I&#x27;m curious why they didn&#x27;t pass a token rather than the actual Lua over the wire via Redis, but it certainly seems to work for them.
rryan超过 11 年前
I may be missing something but I think this could be done more cleanly with an atomic counter or semaphore [1] in Redis.<p><pre><code> 1. Have a task that releases 1 resource to the semaphore every (1.0 &#x2F; cps) seconds. 2. Workers wait to acquire a resource from the semaphore before making a call. </code></pre> Due to the rate of release being fixed at 1&#x2F;cps no worker can ever exceed the calls-per-second limit. Much simpler than sending Lua over the wire.<p>[1] <a href="https://github.com/dv/redis-semaphore" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dv&#x2F;redis-semaphore</a>
评论 #7191563 未加载
hox超过 11 年前
Interestingly enough, Alan Shreve gave a talk at RedisConf a couple of years back detailing something very similar used on the twilio stack to rate limit draining a queue: <a href="https://inconshreveable.com/talks.html" rel="nofollow">https:&#x2F;&#x2F;inconshreveable.com&#x2F;talks.html</a>
wheaties超过 11 年前
So they send code to Redis to make sure that they won&#x27;t increment too high? I know Redis already has a ton of functions prepackaged but this seems like it would be a good one: INCRIF.