varnishcache-friends / varnish3to4

Varnish 3 to 4 migration script
BSD 2-Clause "Simplified" License
125 stars 25 forks source link

Directors and Backends #6

Closed staiyeba closed 6 years ago

staiyeba commented 7 years ago

I'm trying to achieve directors and backends migration to this script.

Here's what I understood about backends and directors in vcl 3 to 4:

In Varnish 3, a director was a group of backends. Varnish chose to serve data from one of the several backends. So several backends are declared. Then a director is declared to do load balancing "logically" from the list of backends.

In varnish 4, the whole concept of directors has been moved to VMOD (Varnish Modules). So you can define several backends and group them together in a director.

Below are examples:

**In varnish 3::**

  probe anyprobe {
    .request   = "GET header/path/to HTTP/1.1"
                 "Host: yourdomain.no"
                 "Connection: close";
    .interval  = 5s;
    .timeout   = 3s;
    .window    = 1;
    .threshold = 1;
    .expected_response = 200;
  }

  backend bk01 {
  .host = "<back.end.ip.01>";
  .port = "82";
  .probe = anyprobe;
  }

  backend bk02 {
  .host = "<back.end.ip.02>";
  .port = "82";
  .probe = anyprobe;
  }

  backend bk03 {
  .host = "<back.end.ip.03>";
  .port = "82";
  .probe = anyprobe;
  }

  director dr_bkend round-robin {
    { .backend = bk01; }
    { .backend = bk02; }
    { .backend = bk03; }
  }

  sub vcl_recv {
   if (req.http.host == "domain.no") {
      error 751 "http://domain.no" + req.url;
   }
   }

**In varnish 4::**

  probe anyprobe {
    .request   = "GET header/path/to HTTP/1.1"
                 "Host: yourdomain.no"
                 "Connection: close";
    .interval  = 5s;
    .timeout   = 3s;
    .window    = 1;
    .threshold = 1;
    .expected_response = 200;
  }

  backend bk01 {
  .host = "<back.end.ip.01>";
  .port = "82";
  .probe = anyprobe;
  }

  backend bk02 {
  .host = "<back.end.ip.02>";
  .port = "82";
  .probe = anyprobe;
  }

  backend bk03 {
  .host = "<back.end.ip.03>";
  .port = "82";
  .probe = anyprobe;
  }

  sub vcl_init {
    new sm_bk01 = saintmode.saintmode(bk01, 10);
    new sm_bk02 = saintmode.saintmode(bk02, 10);
    new sm_bk03 = saintmode.saintmode(bk03, 10);

    new dr_bkend = directors.round_robin();
    dr_bkend.add_backend(sm_bk01.backend());
    dr_bkend.add_backend(sm_bk02.backend());
    dr_bkend.add_backend(sm_bk03.backend());
  }

  sub vcl_recv {
   if (req.http.host == "yourdomain.no") {
      set req.backend_hint = bk01;
    }
    else {
      return (synth(751, "http://yourdomain.no" + req.url));
    }
   }

What has changed?

This in 3:

 director dr_bkend round-robin {
   { .backend = bk01; }
   { .backend = bk02; }
  { .backend = bk03; }
 }

Needs to be replaced with this in 4:

sub vcl_init {
    new sm_bk01 = saintmode.saintmode(bk01, 10);
    new sm_bk02 = saintmode.saintmode(bk02, 10);
    new sm_bk03 = saintmode.saintmode(bk03, 10);

   new dr_bkend = directors.round_robin();
   dr_bkend.add_backend(sm_bk01.backend());
   dr_bkend.add_backend(sm_bk02.backend());
   dr_bkend.add_backend(sm_bk03.backend());
  }

Assuming this is a complete example, is there a way we can achieve this in your varnish3to4 script or your suggestions for a workaround for this? :)

fgsch commented 7 years ago

Sorry for not getting to you sooner. What you have described is correct.

We could implement a separate fixup to deal with directors. Roughly it should:

  1. Extract the type of director (round_robin, random, etc) and reference (variable)
  2. Extract the backends associated with the director and any other parameter (e.g. weight)
  3. Add the imports based on 1
  4. Create a vcl_init with the information from 1 and 2

For point 1 you could have multiple directors. This will affect 3 and 4.

What do you think?

staiyeba commented 7 years ago

Hi, I'm sorry for the late feedback, I have been pondering about it and discussing it with others and we think it sounds really neat! I'm wondering if you are planning to implement it? Because it would be awesome ! Thanx in advance! :)

fgsch commented 6 years ago

Timed-out.