Reputation: 11
I am running an Nginx server to serve video content to users. This nginx server picks content from an upstream server, caches it, also serves to users. All future requests are served from this cache. I have set aside 500GB of space on cache for this. When the cache is full, the nginx cache manager is able to delete old, unused files as per my proxy_cache directive if the cache folder is on the hard drive. When I mount this cache folder on the RAM (tmpfs), nginx is unable to drop the old files. I get an error saying '28: No space left on device'. I have checked the permission of the cached folder both while on the RAM and on the hard drive. It has the same permissions.
proxy_cache_path /cache/12054 keys_zone=a12054:100m levels=1:2 max_size=500g inactive=7d;
If I unmount from RAM it starts working fine again.
Upvotes: 1
Views: 2406
Reputation: 91932
You have too little RAM. You need 500 GB of virtual RAM (physical RAM + swap space) for that configuration to work in tmpfs. Nginx will not try to purge files until they expire or you have reached max_size
. From the manual:
The special “cache manager” process monitors the maximum cache size set by the
max_size
parameter. When this size is exceeded, it removes the least recently used data.
Confirm how large your tmpfs partition is by running df -h
.
You might not need tmpfs for this at all. If you are running a modern operating system all free RAM should automatically be used as a disk cache anyway. Just write the files to disk. They will have to be written sooner or later anyway so it might be more efficient to write them directly instead of waiting for them to be swapped out.
Upvotes: 2