<div dir="ltr"><div style="font-family:arial,sans-serif;font-size:13px">Hello,</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">I've got a question about varnish's director capabilities, and I</div>
<div style="font-family:arial,sans-serif;font-size:13px">was hoping someone here could help me understand the capabilities</div><div style="font-family:arial,sans-serif;font-size:13px">of varnish.</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">Right now we've got a varnish server acting as a load balancer for</div><div style="font-family:arial,sans-serif;font-size:13px">three backends that are supposed to contain identical content.</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">In realiity, small differences can exist as an update process visits</div><div style="font-family:arial,sans-serif;font-size:13px">
each backend in turn, updating its content before proceeding onto</div><div style="font-family:arial,sans-serif;font-size:13px">the next.</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
To minimize the possibility of a request seeing an inconsistent</div><div style="font-family:arial,sans-serif;font-size:13px">view of the backend, we're grouping requests by path to route them</div><div style="font-family:arial,sans-serif;font-size:13px">
to a particular backend. E.g., requests with path /a/ get sent to</div><div style="font-family:arial,sans-serif;font-size:13px">backend #1, requests with path /b/ get sent to backend #2.</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">So we have backend configurations similar to this:</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
backend b1 {</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.host = "<a href="http://b1.example.org/" target="_blank">b1.example.org</a>";</div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="white-space:pre-wrap"> </span>.port = "80";</div><div style="font-family:arial,sans-serif;font-size:13px">}</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
backend b2 {</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.host = "<a href="http://b2.example.org/" target="_blank">b2.example.org</a>";</div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="white-space:pre-wrap"> </span>.port = "80";</div><div style="font-family:arial,sans-serif;font-size:13px">}</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
backend b3 {</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.host = "<a href="http://b3.example.org/" target="_blank">b3.example.org</a>";</div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="white-space:pre-wrap"> </span>.port = "80";</div><div style="font-family:arial,sans-serif;font-size:13px">}</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
And our vcl_recv section has something like this in it:</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">if (req.url ~ "^/(a|b|c|d)[\.\/]") {</div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>set req.backend = b1;</div><div style="font-family:arial,sans-serif;font-size:13px">}</div><div style="font-family:arial,sans-serif;font-size:13px">
else if (req.url ~ "^/(e|f|g|h)[\.\/]") {</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>set req.backend = b2;</div><div style="font-family:arial,sans-serif;font-size:13px">
}</div><div style="font-family:arial,sans-serif;font-size:13px">else </div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>set req.backend = b3;</div><div style="font-family:arial,sans-serif;font-size:13px">
}</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">The problem with our setup is that we would like to introduce fail</div><div style="font-family:arial,sans-serif;font-size:13px">
over capabilities, but it's not clear how to introduce a director</div><div style="font-family:arial,sans-serif;font-size:13px">that route all traffic for path /<x>/ to backend #<n> except in the</div><div style="font-family:arial,sans-serif;font-size:13px">
situation where we detect that backend is down.</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">The documentation discusses a client director, and it seems like</div>
<div style="font-family:arial,sans-serif;font-size:13px">it might be possible to use that to enable our fallback logic.</div><div style="font-family:arial,sans-serif;font-size:13px">Basically to say that, based on the path prefix, to set an identity</div>
<div style="font-family:arial,sans-serif;font-size:13px">of X and consistently route to an available backend. But I'm unclear</div><div style="font-family:arial,sans-serif;font-size:13px">on whether or not the client director will perform any sort of</div>
<div style="font-family:arial,sans-serif;font-size:13px">fallback logic if a backend that it *was* routing to fails its</div><div style="font-family:arial,sans-serif;font-size:13px">probe?</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">Say we define a .probe:</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
backend b1 {</div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.host = "<a href="http://b1.example.org/" target="_blank">b1.example.org</a>";</div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="white-space:pre-wrap"> </span>.port = "80";</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.probe = { </div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="white-space:pre-wrap"> </span>.url = "/";</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.timeout = 34 ms; </div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="white-space:pre-wrap"> </span>.interval = 1s; </div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.window = 10;</div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="white-space:pre-wrap"> </span>.threshold = 8;</div><div style="font-family:arial,sans-serif;font-size:13px"> }</div><div style="font-family:arial,sans-serif;font-size:13px">}</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">backend b2 {</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.host = "<a href="http://b2.example.org/" target="_blank">b2.example.org</a>";</div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.port = "80";</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.probe = { </div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.url = "/";</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.timeout = 34 ms; </div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.interval = 1s; </div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.window = 10;</div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.threshold = 8;</div><div style="font-family:arial,sans-serif;font-size:13px"> }</div><div style="font-family:arial,sans-serif;font-size:13px">
}</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">backend b3 {</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.host = "<a href="http://b3.example.org/" target="_blank">b3.example.org</a>";</div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.port = "80";</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.probe = { </div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.url = "/";</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.timeout = 34 ms; </div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.interval = 1s; </div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.window = 10;</div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.threshold = 8;</div><div style="font-family:arial,sans-serif;font-size:13px"> }</div><div style="font-family:arial,sans-serif;font-size:13px">
}</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">and we set up a client director:</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">director member client {</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>{</div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="white-space:pre-wrap"> </span>.backend = b1;</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.weight = 1;</div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="white-space:pre-wrap"> </span>}</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>{</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.backend = b2;</div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.weight = 1;</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>}</div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>{</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.backend = b3;</div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>.weight = 1;</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>}</div>
<div style="font-family:arial,sans-serif;font-size:13px">}</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">and then we set client.identity based on our regexes:</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">if (req.url ~ "^/(a|b|c|d)[\.\/]") {</div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="white-space:pre-wrap"> </span>set client.identity = "group-1"</div><div style="font-family:arial,sans-serif;font-size:13px">}</div><div style="font-family:arial,sans-serif;font-size:13px">else if (req.url ~ "^/(e|f|g|h)[\.\/]") {</div>
<div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>set client.identity = "group-2"</div><div style="font-family:arial,sans-serif;font-size:13px">}</div><div style="font-family:arial,sans-serif;font-size:13px">
else </div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap"> </span>set client.identity = "group-3"</div><div style="font-family:arial,sans-serif;font-size:13px">}</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">If the backend pool shrinks from 3 to 2 because one of the backend</div><div style="font-family:arial,sans-serif;font-size:13px">
servers fails its probe, will traffic that was getting routed to</div><div style="font-family:arial,sans-serif;font-size:13px">that backend get rerouted?</div><div style="font-family:arial,sans-serif;font-size:13px"><br>
</div><div style="font-family:arial,sans-serif;font-size:13px">Someone has also pointed out to me the fallback director, and how</div><div style="font-family:arial,sans-serif;font-size:13px">it might be possible for us to create several pools to indicate</div>
<div style="font-family:arial,sans-serif;font-size:13px">fail-over order. E.g., set b1 and b2 as one group, and b2 and b3</div><div style="font-family:arial,sans-serif;font-size:13px">and another group, but I'm not grasping exactly how that would look.</div>
<div style="font-family:arial,sans-serif;font-size:13px">It appears as though I'd need to set up multiple directors and use</div><div style="font-family:arial,sans-serif;font-size:13px">restart to trigger fail over if a request to one director failed?</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Jim</div></div>