API throttle RateLimit-Remaining never updates every minutes
Asked Answered
M

0

8

I have an API created with Laravel 5.2. I am using throttle for rate limiting. In my route file, I have set the following..

Route::group(['middleware' => ['throttle:60,1'], 'prefix' => 'api/v1'], function() {
    //
}

As I understood the Laravel throttling, the above script will set the request limit to 60 per minute. I have an application querying the route which repeat every 10 seconds. So, per minute there are 6 request which is much more satisfying the above throttle.

Problem is, my query works until I execute 60 request regardless of time and after 60 request, it responds me 429 Too Many Requests with header Retry-After: 60. As per my understanding, the X-RateLimit-Remaining should update every 1 minute. But it seems never updated until it goes to 0. After become zero, then waits for 60 seconds then updated.

Am I doing anything wrong here.

Merla answered 1/2, 2017 at 11:26 Comment(8)
when you call any api URL, it will decrease the counter, its global counter for all request to server, so if it exceeds 60 request in one minute, need to call again the last called URL, this limit will be again reset to 59 as Remaining, I had made a watch until I see counter to 0 and manage this error "429 Too Many Request" by recalling the last URL callDiscredit
even you can change this limit by editing file app/Http/Kernel.php and change value in 'api' => [ 'throttle:60,1', /* change as 100 per 1 minute if URL usage rate higher then default*/ 'bindings', ],Discredit
@Discredit May be you did not understand my quesion. My problem is it is not resetting every 1 minute as per instruction above.Merla
As per line in your question "As per my understanding, the X-RateLimit-Remaining should update every 1 minute", not its not like this, it works with number of api calls remaining for that one minute, so you can increase this limit you didn't have idea how many time the api will be calledDiscredit
as test case if you call a API URL with once per minute the remaining will always be 59, if you need to call API URLs >60 time for single minute then you will face 429 error, so my suggestion is to increase you limit for API calls, or remove this throttle if its streaming type urlDiscredit
@Discredit as per my question, I have only 10 requests per minute "....querying the route which repeats every 10 seconds". So if I set "'throttle:60,1'", I should never face 429, right? After 1 minute my remaining should be 60 again. But it is not. After 1st minute I see remaining "50", after 2nd minute I see remaining "40" .... after 6 minutes remaining "0" and after 7th minute, it is reset to "remaining 60". Is this behavior correct?Merla
@BlueBird I have the same issue. Did you mange to fix it or find the solution? If one minute passes without any requests, the counter resets, but this is stupid...Claviform
@DobromirHristov, No Really I did not.Merla

© 2022 - 2024 — McMap. All rights reserved.