Rate-limiting minutes issue

Hi,

Iam trying to use the rate_limiting plugin.
{"minute":2,"policy":"cluster","redis_timeout":2000,"hide_client_headers":false,"hour":5,"limit_by":"consumer","redis_port":6379,"redis_database":0,"fault_tolerant":true},"id":"21c00ada-42e8-475b-872f-48d2e147ba4b","route_id":"e26e8fe7-61b6-461e-a3bb-e9b9e3d3f89b","name":"rate-limiting","enabled":true,"consumer_id":"cd3de8f5-aa0d-4424-810b-66173af5c9f3"}

but here the minutes section is not working properly
eg: i have set rate-limit for minutes=2 and hour=5

step1: call the api => works
step2: call the api within same minute => works
step3: call the api again in same minute => rate_limit (success)
step5: call the api next minute=>works
step5: call the api in the same minute=>works
(issue)step6: call the api in the same minute=>works(it should have rate_limited here since it breached 2/minute rate_limit)
step7: call the api next minute=>rate_limit

nginx log:

xxx.xxx.xxx.xxx - - [22/Jun/2018:15:23:29 +0000] "GET /api_page?apikey=<key>&name=Sachin_Tendulkar HTTP/1.1" 200 5216 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"

xxx.xxx.xxx.xxx - - [22/Jun/2018:15:23:41 +0000] "GET /api_page?apikey=<key>&name=Sachin_Tendulkar HTTP/1.1" 200 5216 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"

xxx.xxx.xxx.xxx - - [22/Jun/2018:15:23:50 +0000] "GET /api_page?apikey=<key>&name=Sachin_Tendulkar HTTP/1.1" 429 49 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"

xxx.xxx.xxx.xxx - - [22/Jun/2018:15:28:53 +0000] "GET /api_page?apikey=<key>&name=Sachin_Tendulkar HTTP/1.1" 200 5216 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"

xxx.xxx.xxx.xxx - - [22/Jun/2018:15:29:00 +0000] "GET /api_page?apikey=<key>&name=Sachin_Tendulkar HTTP/1.1" 200 5216 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"

xxx.xxx.xxx.xxx - - [22/Jun/2018:15:29:09 +0000] "GET /api_page?apikey=<key>&name=Sachin_Tendulkar HTTP/1.1" 200 5216 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"

xxx.xxx.xxx.xxx - - [22/Jun/2018:15:29:17 +0000] "GET /api_page?apikey=<key>&name=Sachin_Tendulkar HTTP/1.1" 429 49 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0"

If you check the time of last 4 requests it shows requests within same minute.
Is this the intended behavior?
I was expecting it to work strictly 2/minute and 5/hour

Thanks

Hi,

The rate limiting occurs by “dividing time in periods”, not by “counting backwards from the last request to see how many requests have happened”.

In your example, the first 3 requests where done on minute 23, the next request was done on minute 28, and the last 3 requests where done on minute 29. You are seeing the expected behaviour.