关于nginx cache的命中率
在squid中可以很简单的查看squid的命中率,但是在nginx需要在日志中添加$upstream_cache_status这个参数,这样就可以显示它的cache状态,有
MISS
EXPIRED - expired, request was passed to backend
UPDATING - expired, stale response was used due to proxy/fastcgi_cache_use_stale updating
STALE - expired, stale response was used due to proxy/fastcgi_cache_use_stale
HIT
共这样5种状态。
我的日志文件的格式为:
log_format cache '$remote_addr - $remote_user \[$time_local\] - $request ' 'upstream_response_time $upstream_response_time ' 'msec $msec request_time $request_time - $upstream_cache_status';
在我的日志文件中计算了upstream的响应时间和命中状态。
这样很容易就能从日志中计算出nginx cache的命中率了。
###########################################
Best regards
Timo Seven
()
Linux System Admin & MySQL DBA