大网数据广告活动
服务器运维问答

Nginx: 'no memory in cache keys zone', despite plenty of space

· 52CE 我爱测

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 32…

问题原文

原帖链接 · Jonathan · CC BY-SA 4.0

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.

已采纳解答

原帖链接 · masegaloeh · CC BY-SA 3.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-05-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0 / CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。