<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">Hi,</span><br>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
Thanks to you and all varnish team for such answers that helped me alot,</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
I read the default varnish cache configuration again: <br>
</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
<a href="https://github.com/varnishcache/varnish-cache/blob/6.0/bin/varnishd/builtin.vcl" target="_blank" rel="noopener noreferrer" data-auth="NotApplicable" data-linkindex="0">https://github.com/varnishcache/varnish-cache/blob/6.0/bin/varnishd/builtin.vcl</a></div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
and find out vcl_hash as follow:</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
<br>
</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
```</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
<table>
<tbody>
<tr>
<td><span>sub</span> <span>vcl_hash</span> {</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td><span>hash_data</span>(<span>req.url</span>);</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td><span>if</span> (<span>req.http.host</span>) {</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td><span>hash_data</span>(<span>req.http.host</span>);</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td>} <span>else</span> {</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td><span>hash_data</span>(<span>server.ip</span>);</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td>}</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td><span>return</span> (<span>lookup</span>);</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td>}</td>
</tr>
</tbody>
</table>
<br>
</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
```</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
So, if I change vcl_hash like following , would it be enough for my purpose?(I mean caching the same object from different backends just once with roundrobin directive !:)</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
<br>
</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
```</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
<br>
</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
sub vcl_hash {
<div>    hash_data(req.url);</div>
<div>    return (lookup);</div>
<span>}</span><br>
</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
<table>
<tbody>
<tr>
<td><br>
</td>
</tr>
</tbody>
</table>
</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
```</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
<br>
</div>
<div style="color:black;font-size:12pt;font-family:Calibri,Arial,Helvetica,sans-serif">
By this config I told varnish just cache the content based on the 'req.url' not 'req.http.host' therefore with the same content but different backend varnish would cache once(If I want to use round robin directive instead of shard directive ), Is this true?
 what bad consequences may it cause in the future by this configuration?</div>
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> varnish-misc <varnish-misc-bounces+hrhosseini=hotmail.com@varnish-cache.org> on behalf of Hamidreza Hosseini <hrhosseini@hotmail.com><br>
<b>Sent:</b> Sunday, August 1, 2021 4:17 AM<br>
<b>To:</b> varnish-misc@varnish-cache.org <varnish-misc@varnish-cache.org><br>
<b>Subject:</b> Best practice for caching scenario with different backend servers but same content</font>
<div> </div>
</div>
<style type="text/css" style="display:none">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hi,<br>
I want to use varnish in my scenario as cache service, I have about 10 http servers that serve Hls fragments as the backend servers and about 5 varnish servers for caching purpose, the problem comes in when I use round-robin director for backend servers in
 varnish,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
if a varnish for specific file requests to one backend server and for the same file but to another backend server it would cache that file again because of different Host headers ! so my solution is using fallback director instead of round-robin as follow:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
```</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
In varnish-1:
<div>    new hls_cluster = directors.fallback();</div>
<div>    hls_cluster.add_backend(b1());</div>
<div>    hls_cluster.add_backend(b2());    </div>
<div>    hls_cluster.add_backend(b3());    </div>
<div>    hls_cluster.add_backend(b4());    </div>
<div>    hls_cluster.add_backend(b5());    </div>
<div>    hls_cluster.add_backend(b6());    </div>
<div>    hls_cluster.add_backend(b7());    </div>
<div>    hls_cluster.add_backend(b8());    </div>
<div>    hls_cluster.add_backend(b9());    </div>
<div>    hls_cluster.add_backend(b10());</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>In varnish-2:</div>
<div>    new hls_cluster = directors.fallback();</div>
<div>    hls_cluster.add_backend(b10());</div>
<div>    hls_cluster.add_backend(b1());</div>
<div>    hls_cluster.add_backend(b2());    </div>
<div>    hls_cluster.add_backend(b3());    </div>
<div>    hls_cluster.add_backend(b4());    </div>
<div>    hls_cluster.add_backend(b5());    </div>
<div>    hls_cluster.add_backend(b6());    </div>
<div>    hls_cluster.add_backend(b7());    </div>
<div>    hls_cluster.add_backend(b8());    </div>
<div>    hls_cluster.add_backend(b9());    </div>
<div><br>
</div>
<div><br>
</div>
<div>In varnish-3:</div>
<div>    new hls_cluster = directors.fallback();</div>
<div>    hls_cluster.add_backend(b9());    </div>
<div>    hls_cluster.add_backend(b1());</div>
<div>    hls_cluster.add_backend(b2());    </div>
<div>    hls_cluster.add_backend(b3());    </div>
<div>    hls_cluster.add_backend(b4());    </div>
<div>    hls_cluster.add_backend(b5());    </div>
<div>    hls_cluster.add_backend(b6());    </div>
<div>    hls_cluster.add_backend(b7());    </div>
<div>    hls_cluster.add_backend(b8());    </div>
<div>    hls_cluster.add_backend(b10());</div>
<div><br>
</div>
<span></span>```<br>
But I think this is not the best solution, because there is no load balancing despite, I used different backend for the first argument of fallback directive,<br>
What is varnish recommendation for this scenario?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
</div>
</body>
</html>