3

I am attempting to rate limit queries to the Battle.net API up to their limits of 100 calls/second, 36,000/hour.

My current code looks like this:

var async = require ('async');
var bnet = require ('battlenet-api');

async.eachSeries(regions, function(region, callback) {
    bnet.wow.realmStatusAsync({origin: region}).spread(/*...snip...*/)
});

What I'd need here is to make sure that no calls to battlenet-api run up to the limit, and if so, queue them.

I have looked at timequeue.js, limiter and async's own capabilities and none seems to provide what I am looking for.

Does someone know how to achieve this?

3
  • 1
    So, you want to implement your own limiter to make sure battle.net's rate limiting isn't hit from your service? Commented Aug 23, 2015 at 15:20
  • Not exactly, I'd like to know if there's any solution out there to achieve it. Commented Aug 23, 2015 at 15:43
  • Questions asking for a third party library solution are considered off-topic at StackOverflow. Commented Aug 23, 2015 at 16:17

1 Answer 1

2

A couple possibilities are:

  1. Wait until you get throttled and backoff your requests
  2. Keep track of your limits and used limits inside of your application.

While i think both cases need to be handled, the second one is more valuable, because it will let your application know at any time how many requests have been made for a given timeframe.

You could focus on implementing this on the hour level and letting the backoff/retry catch the cases of going over the 100 req/s timelimit.

To implement this, your application would have to keep track of how many requests are available for the given time period. Before each request the request count has to be checked to see if there are available requests, if there are the API request can be made and if not then no request will be made and your application will throttle itself. Additionally, the limits need to be reset when appropriate.

There are quite a few articles on using redis to accomplish this, a quick google search should uncover them

Sign up to request clarification or add additional context in comments.

1 Comment

Please provide links to the articles you mentioned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.