Correct usage of the Shard director

Mark Hanford mark at hanfordonline.co.uk
Thu Mar 30 12:11:07 CEST 2017


Hi folks. I am transitioning to v5 VCL, and the shard directors look
useful. In our case, we have several products behind Varnish, so I create a
bunch of directors:

    sub vcl_init {
        new product_a_director = directors.shard();
        product_a_director.add_backend(web01);
        product_a_director.add_backend(web02);
        product_a_director.reconfigure();

        new product_b_director = directors.shard();
        product_b_director.add_backend(web03);
        product_b_director.add_backend(web04);
        product_b_director.reconfigure();
    }

Then, later on in my vcl_recv, I have to make a bunch of decisions based on
the host and URL to determine which set of backends to send the request to:


    if (req.http.host == "product_a.mydomain.com") {
        set req.backend_hint = product_a_director.backend();
    }

    if (req.url ~ "^/login.*") {
        set req.backend_hint = product_b_director.backend();
    }

In reality, there are thirteen directors for various products and product
areas, which direct traffic to various combinations of the 15 backends to
separate workloads or to route to servers with particular configuration.

It is important for us that traffic from a particular IP goes to the same
backend in each director whenever possible, so do I have to use the manual
"key" property of the shard director? That would change the above to:

    if (req.http.host == "product_a.mydomain.com") {
        set req.backend_hint = product_a_director.backend(KEY,
product_a_director.key(client.ip));
    }

    if (req.url ~ "^/login.*") {
        set req.backend_hint = product_b_director.backend(KEY,
product_b_director.key(client_ip));
    }

Is that the correct way to lock a client to a backend? I do not want to use
session cookies, this should transcend sessions, so all traffic from one IP
goes to the same backend (if healthy/available/possible).

Thanks,

Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20170330/93e201cf/attachment.html>


More information about the varnish-misc mailing list