2

I'm repeatedly seeing this error in my nginx logs:

[crit] 30165#0: ngx_slab_alloc() failed: no memory in cache keys zone "api-data-cache"

Looking at the directory used for the cache key zone, I can see it's hovering around the 326MB mark:

du -s /usr/local/nginx/cache/
326652

However my nginx.conf specifies a max_size of 1GB, so there should be plenty of room:

proxy_cache_path        /usr/local/nginx/cache levels=1:2 keys_zone=api-data-cache:8m max_size=1g inactive=600m;
proxy_cache_key         "$scheme$host$request_uri/$device_type$cookie_w3tc_referrer";
proxy_cache_use_stale   updating timeout http_500 http_502 http_503 http_504;
proxy_ignore_headers    X-Accel-Expires Expires Cache-Control;

What could be going on here? There's plenty of disk space available (>50GB free) and after finding nothing relevant in the documentation, I'm at a bit of a loss.

Jonathan
  • 1,309
  • 2
  • 22
  • 29

1 Answers1

3

You need to increase the size of shared memory on keys_zone instead of max_size.

Stealing answer from this thread

keys_zone=api-data-cache:8m was defining shared memory zone named api-data-cache with maximum size 8 MB. It holds all active keys and metadata of the cache. So, whenever nginx checks if a page was cached, it consults the shared memory zone first, then seek the location of actual cache in /usr/local/cache/nginx if cache exist.

From the official documentation, it says one megabyte zone can store about 8 thousand keys. So, depending on your application you need to increase it as needed.

masegaloeh
  • 18,236
  • 10
  • 57
  • 106