<div dir="ltr">I think this solves the issue: <a href="http://hg.nginx.org/nginx/rev/9552758a786e">http://hg.nginx.org/nginx/rev/9552758a786e</a><div><br></div><div>Thanks,</div><div><br></div><div>JP<br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 15, 2017 at 11:05 AM, Jean-Paul Hemelaar <span dir="ltr"><<a href="mailto:hemelaar@desikkel.nl" target="_blank">hemelaar@desikkel.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><span style="font-size:12.8px">Hi,</span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I noticed a delay of approx. 200ms when the proxy_cache_background_upd<wbr>ate is used and Nginx sends stale content to the client.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Current setup:</div><div style="font-size:12.8px">- Apache webserver as backend sending a slow response delay.php that simply waits for 1 second: <?php usleep(1000000); ?></div><div style="font-size:12.8px">- Nginx in front to cache the response, and send stale content it the cache needs to be refreshed.</div><div style="font-size:12.8px">- wget sending a request from another machine</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Nginx config-block:</div><div style="font-size:12.8px"><div> location /delay.php {</div><div> proxy_pass <a href="http://backend/" target="_blank">http://backend</a>;</div><div> proxy_next_upstream error timeout invalid_header;</div><div> proxy_redirect http://$host:8000/ http://$host/;</div><div> proxy_buffering on;</div><div> proxy_connect_timeout 1;</div><div> proxy_read_timeout 30;</div><div> proxy_cache_background_update on;</div><div><br></div><div> proxy_http_version 1.1;</div><div> proxy_set_header Connection "";</div><div><br></div><div> proxy_cache STATIC;</div><div> proxy_cache_key "$scheme$host$request_uri";</div><div> proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;</div><div> proxy_set_header Host $host;</div><div> proxy_set_header X-Real-IP $remote_addr;</div><div> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</div><div> proxy_set_header Accept-Encoding "";</div><div><br></div><div> # Just to test if this caused the issue, but it doesn't change</div><div> tcp_nodelay on;<br></div><div> }</div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Wget request: time wget --server-response --output-document=/dev/null "<a href="http://www.example.com/delay.php?teststales=true" target="_blank">http://www.example.com/delay.<wbr>php?teststales=true</a>"</div><div style="font-size:12.8px">Snippet of wget output: X-Cached: STALE</div><div style="font-size:12.8px">Output of time command: real<span class="gmail-m_1522209985367653453gmail-m_1509804073715055244gmail-m_1504950083846086077gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>0m0.253s<br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div>Wget request: time wget --server-response --output-document=/dev/null "<a href="http://www.example.com/delay.php?teststales=true" target="_blank">http://www.example.com/delay.<wbr>php?teststales=true</a>"</div><div>Snippet of wget output: X-Cached: UPDATING</div><div>Output of time command: real<span class="gmail-m_1522209985367653453gmail-m_1509804073715055244gmail-m_1504950083846086077gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>0m0.022s<br></div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">So a cache HIT (not shown) or an UPDATING are fast, sending a STALE response takes some time.<br></div><div style="font-size:12.8px">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.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I'm running version 1.11-10 with the patch provided by Maxim: <a href="http://hg.nginx.org/nginx/rev/8b7fd958c59f" target="_blank">http://hg.nginx.org/ngi<wbr>nx/rev/8b7fd958c59f</a></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Any idea's on this?</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Thanks,</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Jean-Paul</div></div>
</blockquote></div><br></div></div></div>