<div dir="ltr"><div>Hi!</div><div><br></div><div>Thanks for sharing patches. It's interesting for me and I'm going to test it soon.</div><div>For this particular patch I would suggest to reduce the scope of mutex locking</div><div>and remove it when "serve_tempfile" is not configured. See my version below:</div><div><span style="font-family:monospace"><span style="font-weight:bold;color:rgb(0,0,0);background-color:rgb(255,255,255)">diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="font-weight:bold;color:rgb(0,0,0);background-color:rgb(255,255,255)">index db379450..97982aed 100644</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="font-weight:bold;color:rgb(0,0,0);background-color:rgb(255,255,255)">--- a/src/http/ngx_http_file_cache.c</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="font-weight:bold;color:rgb(0,0,0);background-color:rgb(255,255,255)">+++ b/src/http/ngx_http_file_cache.c</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,178);background-color:rgb(255,255,255)">@@ -460,6 +460,22 @@</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)"> ngx_http_file_cache_open(ngx_http_request_t *r)
</span><br> goto done;
<br> }
<br> <br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+ if (c->serve_tempfile) {</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+ ngx_shmtx_lock(&cache->shpool->mutex);</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+ if (c->node->updating) {</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+ /* Do not try old cached file, jump directly to cache_lock and use tempfile */</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+ test = 0;</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+ }</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+ ngx_shmtx_unlock(&cache->shpool->mutex);</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+ if (!test) {</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+ rv = NGX_DECLINED;</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+ goto done;</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+ }</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+ }</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br><span style="color:rgb(24,178,24);background-color:rgb(255,255,255)">+</span><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">
</span><br> rc = ngx_http_file_cache_open_file(r, &c-><a href="http://file.name">file.name</a>);
<br> if (rc != NGX_DECLINED) {
<br> return rc;<br>
<br></span></div><div><span style="font-family:monospace">Best wishes,</span></div><div><span style="font-family:monospace">Vadim<br></span></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">пт, 28 янв. 2022 г. в 17:00, Jiří Setnička via nginx-devel <<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"># HG changeset patch<br>
# User Jiří Setnička <<a href="mailto:jiri.setnicka@cdn77.com" target="_blank">jiri.setnicka@cdn77.com</a>><br>
# Date 1643385660 -3600<br>
# Fri Jan 28 17:01:00 2022 +0100<br>
# Node ID 5e64af4c94860cd5cf4b9af5a265d3a087e7b735<br>
# Parent 0e00ffe7fab3dcf3d3167851237327e5fb9e10b6<br>
Tempfiles: Skip cached file if there is already newer tempfile<br>
<br>
diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c<br>
--- a/src/http/ngx_http_file_cache.c<br>
+++ b/src/http/ngx_http_file_cache.c<br>
@@ -455,6 +455,20 @@ ngx_http_file_cache_open(ngx_http_reques<br>
goto done;<br>
}<br>
<br>
+ ngx_shmtx_lock(&cache->shpool->mutex);<br>
+<br>
+ if (c->serve_tempfile && c->node->updating) {<br>
+ /* Do not try old cached file, jump directly to cache_lock and use tempfile */<br>
+ test = 0;<br>
+ }<br>
+<br>
+ ngx_shmtx_unlock(&cache->shpool->mutex);<br>
+<br>
+ if (!test) {<br>
+ rv = NGX_DECLINED;<br>
+ goto done;<br>
+ }<br>
+<br>
rc = ngx_http_file_cache_open_file(r, &c-><a href="http://file.name" rel="noreferrer" target="_blank">file.name</a>);<br>
if (rc != NGX_DECLINED) {<br>
return rc;<br>
_______________________________________________<br>
nginx-devel mailing list -- <a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
To unsubscribe send an email to <a href="mailto:nginx-devel-leave@nginx.org" target="_blank">nginx-devel-leave@nginx.org</a><br>
</blockquote></div>