2014-07-23 51 views
0

$upstream_cache_status是HIT,但$request_time有时会持续5秒,有什么问题?

我的nginx.conf

http { 
    include  mime.types; 
    default_type application/octet-stream; 

    sendfile  on; 
    #tcp_nopush  on; 

    keepalive_timeout 65; 

    gzip on; 

    client_max_body_size 30M; 

    proxy_temp_path /tmp/proxy_temp_dir; 
    proxy_cache_path /tmp/proxy_cache_dir levels=1:2 keys_zone=cache:500m inactive=1d max_size=500m; 

    log_format cache_log '$remote_addr - [$request_time] $status $upstream_cache_status "$request"'; 

    server { 
     access_log logs/access.log cache_log; 
     error_log logs/error.log error; 

     proxy_cache cache; 
     proxy_cache_valid 10m; 

     location/{ 
      proxy_next_upstream http_502 error timeout; 
      proxy_http_version 1.1; 
      proxy_set_header Connection ""; 
      proxy_set_header Host $host; 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

      proxy_pass http://xxxxxx; 
     } 
    } 

    include /usr/local/openresty/nginx/conf/vhosts/*.conf; 
} 

而且access.log的:

x.x.x.x - [5.076] 200 HIT "GET /xxx" 
x.x.x.x - [0.092] 200 HIT "GET /xxx" 

相同的请求URL,两者都命中缓存,为什么$request_time最后5秒以上?

谢谢。

+0

它总是第一次打?我会说被调用的元素没有被缓存。 – Ota

+0

记录'$ upstream_response_time'。它是否第一次请求该网址很长一段时间?它可能是硬盘延迟? –

+0

@AlexeyTen所有HIT请求的$ upstream_response_time都为空。 – fannheyward

回答

0

这是一个磁盘IO问题,我将proxy_cache_path移动到另一个SSD并解决了问题。