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
[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"
proxy_cache_path /usr/share/nginx/cache levels=1:1:2 keys_zone=PAGES:50m inactive=7d max_size=900m;
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_zoneover time. If we make the
max_sizesmall enough will it stop creating new entries in
keys_zone, and instead overwrite existing ones?
- Does the
inactiveparam have anything too due with
keys_zone? Since our inactive set pretty long, does this keep the entries in
- Is there a way to purge the
keys_zonerecords without restarting NGINX?