Reputation: 71
Nginx cache locked requests(http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_lock) always takes 500ms to respond
$ab -n 2 -c 2 http://192.168.12.103/test1234
access.log:
192.168.12.103 - - [12/Sep/2017:02:34:59 -0700] "GET /test1234 HTTP/1.0" 200 12 "-" "ApacheBench/2.3" "-" 127.0.0.1:9095 0.002 0.002 MISS
192.168.12.103 - - [12/Sep/2017:02:34:59 -0700] "GET /test1234 HTTP/1.0" 200 12 "-" "ApacheBench/2.3" "-" - - 0.502 HIT
I know that it buffers to a temp file and copies it to the cache. But 500ms looks large. Anybody knows why?
Any help would be appreciated.
Setup info:
nginx config
worker_processes 1;
error_log logs/error.log;
daemon off;
pid /var/run/nginx.pid;
events {}
http {
proxy_cache_path /tmpfs/local_cache keys_zone=local_cache:250m levels=1:2 inactive=8s max_size=1G;
proxy_temp_path /tmpfs;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'$upstream_addr $upstream_response_time $request_time $upstream_cache_status';
access_log logs/access.log main;
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:9095;
proxy_cache local_cache;
proxy_cache_valid 200 2s;
proxy_cache_lock on;
}
}
}
Upvotes: 0
Views: 2788
Reputation: 11
It's now 2023 and it's still not possible to change the default value using a parameter. The default value of 500 ms is found in ngx_http_file_cache.c#L455 and ngx_http_file_cache.c#L515.
You can set the required value and compile nginx yourself. Example of nginx compilation with custom cache lock polling delay - Dockerfile.
Upvotes: 0
Reputation: 71
This seems to be the default behaviour. The cache locked requests are locked by worst case 500ms or the time_out value.(source)
If the upstream response times are stable, for cache_lock_timeout any value little above the response time, it will avoid the behaviour. In this particular case we can set about 5ms and the first request will return in 0-1 ms and the locked requests will return within 5-6ms.
Upvotes: 1