Page MenuHomePhabricator

api-gateway chart: support rate limits for multiple time units
Closed, ResolvedPublic

Description

It should be possible to configure separate limits per second, minute, and hour (and maybe also per day). This can be achieved by specifying the time unit as a key in the rate limit descriptor. In the values file, the structure of the rate limit definition would change as follows:


#OLD
    #anon_limit:
     # requests_per_unit: 500
     # unit: HOUR
    #default_limit:
     # requests_per_unit: 5000
     # unit: HOUR

#NEW
    anon_limit:
       HOUR: 500
       MINUTE: 50
    default_limit:
       HOUR: 5000
       MINUTE: 500

Event Timeline

@HCoplin-WMF @JTweed-WMF I filed this task because I expect that we will need this ability, but if you tell me that we don't, it makes my life easier...

For the per-second limits, keep in mind that we use them as a stand-in for proper concurrency control. Perhaps @Joe or @akosiaris can say how important that is, given that we already have per-IP limits enforced at the edge.

FWIW, implementing this adds complexity to the configuration, but not a terrible lot.

We currently have hourly limits in place that would potentially cause load spikes at the beginning of each hour:

grafik.png (409×821 px, 63 KB)

The graph shows the number of "over limit" requests dropping at the start of every hour. Once we start enforcing limits, that means that the number of "within limit" requests will be highest at the start of the hour.

I think that this proves we should try a requests/second or requests/minute limit, to try and smooth out usage and avoid a spike every hour.

My hunch is that this is not just the hourly limit evenly spread, we need to give people the ability to burst to some degree.

I'd like to try a few requests/second limit, to see where we should set it. Something in the region of 5-15rps as a test?

Change #1205191 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[operations/deployment-charts@master] WIP: rest-gateway: allow rate limits per time unit

https://gerrit.wikimedia.org/r/1205191

Change #1205191 merged by jenkins-bot:

[operations/deployment-charts@master] rest-gateway: allow rate limits per time unit

https://gerrit.wikimedia.org/r/1205191

daniel claimed this task.

Deployed and tested. We still only use per-hour limits in production though.