I’m curious about the behaviour of the “local” rate limiting policy.
Every time a request is processed, a counter is either created or incremented in the
kong_rate_limiting_counters shared-memory dictionary. See this line in the Kong source code.
This code is using LuaResty’s
shm:incr function, documented here. Note that the function accepts an optional TTL, but in this case no TTL is specified so the value will not expire.
Unless I’m missing something, this means the dictionary will grow in an unbounded manner. However, I notice here that the shared memory zone is created with a size of 12 MB. So my question is, what happens when the dictionary grows to fill that space? Is it smart enough to expire old entries using LRU or something similar? Or will it stop accepting new entries, meaning the rate limiting logic stops working? Or does nginx just crash? Or something else?
As an aside, I think it would make sense to set a TTL when calling
shm:incr. The appropriate TTL can be trivially calculated based on the rate limiting period: if it’s a per-minute metric, set the TTL to one minute.
As another aside, the “cluster” policy exhibits a similar problem. It writes rate limiting metrics to postgres but never deletes them, so we have to run a nightly job to clean them up and prevent the DB from filling its disk. Correction: it looks like a periodic DB cleanup task was added in 0.15.x.