关于nginx cache的命中率

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

  1. MISS
  2. EXPIRED – expired, request was passed to backend
  3. UPDATING – expired, stale response was used due to proxy/fastcgi_cache_use_stale updating
  4. STALE – expired, stale response was used due to proxy/fastcgi_cache_use_stale
  5. 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
blog: http://www.timoseven.com
twitter: http://twitter.com/zauc
Linux System Admin & MySQL DBA

关于 Timo
XNIX SA & MYSQL DBA

4 Responses to 关于nginx cache的命中率

  1. guest说道:

    还有bypass和updating呢?

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: