在squid中可以很简单的查看squid的命中率,但是在nginx需要在日志中添加$upstream_cache_status这个参数,这样就可以显示它的cache状态,有

  1.  

  2. MISS
  3.  

  4. EXPIRED – expired, request was passed to backend
  5.  

  6. UPDATING – expired, stale response was used due to proxy/fastcgi_cache_use_stale updating
  7.  

  8. STALE – expired, stale response was used due to proxy/fastcgi_cache_use_stale
  9.  

  10. HIT
  11.  

共这样5种状态。
我的日志文件的格式为:

 

1 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的命中率了。

转载自:http:///2010/08/16/关于nginx-cache的命中率/