I am using nginx to cache requests to my uwsgi backend using
uwsgi_cache_path /var/cache/nginx/uwsgi keys_zone=cache:15M max_size=5G;
My back-end is setting a very long expires header (1 year+). However, as my system runs, I see the cache topping out at 15M. It gets up to that level, then prunes down to 10M.
This causes a lot of unnecessary calls to my back end. When I change the keys_zone size it seems to control the size of the entire cache. It seems to ignore the max_size and instead substitute the keys_zone size. (*)
Can anyone explain this behavior? Is there a known bug in this version? Am I missing the point? I don't want to allocate 5G to the cache manager..
# nginx -V
nginx version: nginx/1.2.0
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
TLS SNI support enabled
configure arguments: --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --user=www-data --group=www-data --with-http_ssl_module --with-http_stub_status_module
(*) Update: I guess this was my overactive imagination trying to find a pattern in the chaos.
By default, NGINX Plus and NGINX take a safe and cautious approach to content caching. They cache content retrieved by a GET or HEAD request, without a Set-Cookie response, and cache time is defined by the origin server headers ( X-Accel-Expires , Cache-Control , and Expires ).
Responses are cached the first time a request is made, and remain valid indefinitely. In contrast, responses to requests served by backend2 change frequently, so they are considered valid for only 1 minute and aren't cached until the same request is made 3 times.
Enabling nginx caching is recommended only for websites with a specific profile (for example, popular blogs or news websites): High traffic. The content is updated every few seconds.
Expires header (and some other headers) is honoured by nginx to determine if a response is cacheable, but it's not used to determine how long to cache it.
By default, your inactive cache will be deleted after 10 min. Could you increase that number to see if it makes a difference?
proxy_cache_path path [levels=levels] keys_zone=name:size [inactive=time] [max_size=size] [loader_files=number] [loader_sleep=time] [loader_threshold=time];
Cached data that are not accessed during the time specified by the inactive parameter get removed from the cache regardless of their freshness. By default, inactive is set to 10 minutes.
Reference: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With