<div dir="ltr">Hi,<div><br></div><div>There are a lot of things to unpack here.</div><div><br></div><div>> 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</div><div><br></div><div>The two aren't related, if you have a hashing problem causing you to cache the same object twice, changing the directors isn't going to save you. Ideally, the requests will get normalized (host header and path) in vcl_recv{} so that they will be properly hashed in vcl_hash{}.</div><div><br></div><div>The backend resolution only happens after you have exited vcl_backend_fetch{}, long after you have (not) found the object in the cache, and the best solution for video is usually to use consistent-hashing. In open-source this means vmod_shard (<a href="https://varnish-cache.org/docs/trunk/reference/vmod_directors.html#directors-shard">https://varnish-cache.org/docs/trunk/reference/vmod_directors.html#directors-shard</a>), in Enterprise, it'll be udo (<a href="https://docs.varnish-software.com/varnish-cache-plus/vmods/udo/#set-hash">https://docs.varnish-software.com/varnish-cache-plus/vmods/udo/#set-hash</a>), they are going to handle about the same except udo makes it easier to set the hash, which may be important for live (more info below).</div><div><br></div><div>With consistent hashing, you can configure all Varnish servers the same, and they will determine which backend to use based on the request. Typically, the same request will always go to the same backend. This provides pretty good load-balancing over time, and additionally it leverages the internally caching that most video origins have.</div><div><br></div><div>If you are serving VOD, that is all you need, but if you are serving Live, you need to care about one other thing: you want consistent hashing not per request, but per stream. Because the origins may be slightly out of sync, you may get a manifest on origin A which will advertise a chunk that isn't available anywhere yet, and if you don't fetch the new chunk from origin A, you'll get a 404 or a 412.</div><div>So, for live, you will need to use shard's key() (<a href="https://varnish-cache.org/docs/trunk/reference/vmod_directors.html#int-xshard-key-string">https://varnish-cache.org/docs/trunk/reference/vmod_directors.html#int-xshard-key-string</a>) or udo's set_hash() (<a href="https://docs.varnish-software.com/varnish-cache-plus/vmods/udo/#set-hash">https://docs.varnish-software.com/varnish-cache-plus/vmods/udo/#set-hash</a>) to create a hash based on the stream path.</div><div><br></div><div>For example, consider these paths:</div><div>- /live/australia/Channel5/480p/manifest.m3u8 and /live/australia/Channel5/480p/chunk_43212123.ts: the stream path is /live/australia/Channel5/480p/</div><div>- /video/live/52342645323/manifest.dash and /video/live/52342645323/manifest.dash?time=4216432432&bitrate=80000000&audio=523453: the stream path is /video/live/52342645323/manifest.dash</div><div><br></div><div>On top of all this, if you start having more than 5 Varnish servers, you might want to consider adding an extra layer of caching between the client-facing Varnish nodes and the origins (origin shields) to reduce the load on the origins. In that case, the shields would be the one handling the consistent hashing.</div><div><br></div><div>Hope this helps</div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>-- <br></div>Guillaume Quintard<br></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Aug 1, 2021 at 4:18 AM Hamidreza Hosseini <<a href="mailto:hrhosseini@hotmail.com">hrhosseini@hotmail.com</a>> wrote:<br></div><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">
<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>
_______________________________________________<br>
varnish-misc mailing list<br>
<a href="mailto:varnish-misc@varnish-cache.org" target="_blank">varnish-misc@varnish-cache.org</a><br>
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" rel="noreferrer" target="_blank">https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</a><br>
</blockquote></div>