0

I just wanted to make sure this is the most ideal way to accomplish this.

Here's the setup: Basically we have 3 servers "balanced" by DNS Round Robin. Varnish is configured on each server with a standard lamp stack behind it.

Basically when a request comes in we check if the default backend is healthy, if not then we fall back to our director which round robins the other two servers till the default backend is healthy again. So we just want Varnish to always use localhost unless our backend isn't healthy. Here's my code:

probe healthcheck {
   .url = "/info.php";
        .timeout = 1s;
        .interval = 4s;
        .window = 5;
        .threshold = 3;
        .expected_response = 200;
}

# Default backend definition. Set this to point to your content server.
backend default {
    .host = "127.0.0.1";
    .port = "8080";
    .probe = healthcheck;
}

#Cluster nodes
backend lamp02 {
  .host  = "192.168.0.102";
  .port = "8080";
  .probe = healthcheck;
}
backend lamp03 {
  .host  = "192.168.0.103";
  .port = "8080";
  .probe = healthcheck;
}

sub vcl_init {
    new server_pool  = directors.round_robin();
    server_pool.add_backend(lamp02);
    server_pool.add_backend(lamp03);
}

sub vcl_recv {
    # Happens before we check if we have this in cache already.
    #
    # Typically you clean up the request here, removing cookies you don't need,
    # rewriting the request, etc.

    if (!std.healthy(req.backend_hint)) {
      set req.backend_hint = server_pool.backend();
    } else {
      set req.backend_hint = default;
    }
}

Is this the most efficient way to do this?

Thanks!

0

Yes. You could do it positively instead of negatively, which might read better if your VCL becomes complex, but your method is good.

if (std.healthy(req.backend_hint)) {
  set req.backend_hint = default;
} else {
   set req.backend_hint = server_pool.backend();
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.