Rate limit exceeded, how does it work

Hello, i am trying to execute multiple request for direction but i don’t understand why i get the “Rate limit exceeded” error when i specifically limite my request by 40 per min.

in my code i take the current timestamp then i do my request until i reach 40 request, after that i calcul the dirrerence between my first timestamp with the current time ans i wait until i have a 60sec between now and my first request. then i repeat the same processe with the next 40 request.

that should work but it down not and break after about 200 requests. i tried 30 request per min, same problem. should i calculate the 60sec in another way ?

Thanks for your help.

Hey,

if I’m not mistaken, you can imagine having 40 “slots” of requests, each with a 60s timer attached to it.
If you issue a request, it takes up one of the “slots” and blocks it for 60 seconds.

Once you’ve issued 40 requests, all 40 slots will be blocked and will become unblocked one after the other.

What I think happens here is that after waiting for 60 seconds starting with your first request, some slots are still blocked since their 60s timer hasn’t run out.

Example

As an example, assume the second request taking 30s by chance, and all others finishing “instantly”. The first slot and second slot would then be free shortly after the 60s have passed, but the other 38 would still have ~30s on their clock, since they started 30s after the first request.

If you then issue another 40 requests, with all going through “instantly”, you’ll run into your rate limit after just 2 requests, since only two slots are free, but the others are still blocked.

I’d recommend waiting for 60s after your last request, so you know that all 40 slots will be free again.
This will slightly increase the time needed for your analysis, but given that you’re actually using the minutely rate limit, you’ll run into the daily rate limit of 2000 requests anyways :wink:

This daily rate limit resets 24 hours after the first request since the last reset.

Best regards

1 Like

Hi @jschnell ,
thank you so much for your answer,
I had no idea it worked that way.
I did not see this information in the documentation, if this is really how it works, I hope this post can enlighten others in the future(maybe someone could add this info in the official doc).

I will try to implement a pool system to allocate slots properly as they become available.
a let you know if this is the way to go.
thank you again!

Hey,

glad I could help.
Implementing such a “pool” might seem like a good idea, but I really think that waiting 60s after the last request is sufficient to not run into rate limiting issues, and should be way easier to implement.

If you decide to go forward with that, I’m indeed interested in your findings though :slight_smile:
Best regards

hello again,
I implemented my pool of slots and it works great, it was no more complicated than what I tried to do previously with my waiting system.
I would have put an example of code but I program in WLanguage and therefore it is in French. I doubt it will be very useful for the English-speaking community.

thanks again.

1 Like