Difference between adjusting set req backend in vcl_recv and vcl_backend_fetch

Hamidreza Hosseini hrhosseini at hotmail.com
Mon Sep 6 14:21:11 UTC 2021


Hi,
This is part of my varnish configuration file for sharding:

```
cat /etc/varnish/default.vcl

vcl 4.1;

import directors;


probe myprobe {
    .request =
      "HEAD /healthcheck.php HTTP/1.1"
      "Connection: close"
      "User-Agent: Varnish Health Probe";
    .timeout = 1s;
    .interval = 5s;
    .window = 5;
    .threshold = 3;
}


backend b-01 { .host = "b-01"; .port = "80"; .probe = myprobe; }
backend b-02 { .host = "b-02"; .port = "80"; .probe = myprobe; }
backend b-03 { .host = "b-03"; .port = "80"; .probe = myprobe; }


sub vcl_init {


  new hls_cluster = directors.shard();
    hls_cluster.add_backend(b-01);
    hls_cluster.add_backend(b-02);
    hls_cluster.add_backend(b-03);


  new p = directors.shard_param();

    hls_cluster.set_rampup(30s);
#    hls_cluster.set_warmup(0.5);

    hls_cluster.reconfigure();
    hls_cluster.associate(p.use());

}



acl purge {
    "localhost";
}


sub vcl_recv {

   set req.backend_hint = hls_cluster.backend();

}


sub vcl_backend_fetch {

  p.set(by=KEY, key=hls_cluster.key(bereq.url));
  set bereq.backend = hls_cluster.backend(resolve=LAZY, healthy=CHOSEN);

}

```
1. there are two set backend in this config, one is on vcl_recv:
"set req.backend_hint = hls_cluster.backend();"
and one in vcl_backend_fetch:
"set bereq.backend = hls_cluster.backend(resolve=LAZY, healthy=CHOSEN);"
should I remove set in vcl_recv cause I think if I adjust it , all requset will go through this backend list and configs like healthy=CHOSEN in vcl_backend_fetch wouldnt be applied! Am I true?

2.Actually what is difference between vcl_backend_fetch and vcl_recv?

3.should I remove "set req.backend_hint" from vcl_recv?

Best regards,Hamidreza


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


More information about the varnish-misc mailing list