200ms delay when serving stale content and proxy_cache_background_update enabled

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

200ms delay when serving stale content and proxy_cache_background_update enabled

Jean-Paul Hemelaar
Hi,

I noticed a delay of approx. 200ms when the proxy_cache_background_update is used and Nginx sends stale content to the client.

Current setup:
- Apache webserver as backend sending a slow response delay.php that simply waits for 1 second: <?php usleep(1000000); ?>
- Nginx in front to cache the response, and send stale content it the cache needs to be refreshed.
- wget sending a request from another machine

Nginx config-block:
    location /delay.php {
     proxy_pass  http://backend;
     proxy_next_upstream error timeout invalid_header;
     proxy_redirect http://$host:8000/ http://$host/;
     proxy_buffering on;
     proxy_connect_timeout 1;
     proxy_read_timeout 30;
     proxy_cache_background_update on;

     proxy_http_version 1.1;
     proxy_set_header Connection "";

     proxy_cache            STATIC;
     proxy_cache_key        "$scheme$host$request_uri";
     proxy_cache_use_stale  error timeout invalid_header updating http_500 http_502 http_503 http_504;
     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_set_header        Accept-Encoding  "";

     # Just to test if this caused the issue, but it doesn't change
     tcp_nodelay on;
   }

Wget request: time wget --server-response --output-document=/dev/null "http://www.example.com/delay.php?teststales=true"
Snippet of wget output: X-Cached: STALE
Output of time command: real 0m0.253s

Wget request: time wget --server-response --output-document=/dev/null "http://www.example.com/delay.php?teststales=true"
Snippet of wget output: X-Cached: UPDATING
Output of time command: real 0m0.022s

So a cache HIT (not shown) or an UPDATING are fast, sending a STALE response takes some time.
Tcpdump showed that all HTML content and headers are send immediately after the request has been received, but the last package will be delayed; that's why I tested the tcp_nodelay option in the config.

I'm running version 1.11-10 with the patch provided by Maxim: http://hg.nginx.org/nginx/rev/8b7fd958c59f

Any idea's on this?

Thanks,

Jean-Paul

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Loading...