Nginx缓存命中,$request_time较长。

$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 秒或更长时间?

谢谢。

点赞
用户380774
用户380774

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

2014-07-25 02:20:15