We have a very dynamic and high-traffic application and are using NGINX caching with dynamic URLS. We want to cache these URLs for repeated requests.
We have run into an issue a couple times while scaling where we reach the max entries in the keys_zone
and then the server then starts throwing 500 errors and blank responses from the server for new URLs/files that have never been requested before. See Nginx: 'no memory in cache keys zone', despite plenty of space for reference
Example errors:
[crit] 30568#0: ngx_slab_alloc() failed: no memory in cache keys zone "PAGES"`
[alert] 27697#27697: could not allocate node in cache keys zone "PAGES"
Our cache:
proxy_cache_path /usr/share/nginx/cache levels=1:1:2 keys_zone=PAGES:50m inactive=7d max_size=900m;
Expanding keys_zone
size or restarting temporarily fixes the issue. But we are looking to maintain a fixed cache that purges old unused entries versus expanding the keys_zone to support every file/URL we could serve.
Questions if anyone has context of how the NGINX inner-workings:
- I understand that we are creating too many keys in the
keys_zone
over time. If we make themax_size
small enough will it stop creating new entries inkeys_zone
, and instead overwrite existing ones? - Does the
inactive
param have anything too due withkeys_zone
? Since our inactive set pretty long, does this keep the entries inkeys_zone
? - Is there a way to purge the
keys_zone
records without restarting NGINX?