caching - Nginx cache lock always causes 500ms delay -
nginx cache locked requests(http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_lock) takes 500ms 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 buffers temp file , copies cache. 500ms looks large. knows why?
appreciated.
setup info:
- test upstream server
- cache located in tmpfs (mount -t tmpfs -o size=512m tmpfs /tmpfs)
- nginx version: 1.7.2.1
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; } } }
this seems default behaviour. cache locked requests locked worst case 500ms or time_out value.(source)
if upstream response times stable, cache_lock_timeout value little above response time, avoid behaviour. in particular case can set 5ms , first request return in 0-1 ms , locked requests return within 5-6ms.
Comments
Post a Comment