Two-Minute Tech Tuesdays - UDO

In this week’s episode of Two-Minute Tech Tuesday, we'll talk about UDO which is short for "Unified Director Object".

 

UDO is a Varnish Enterprise VMOD that performs flexible load balancing, this means that Varnish can connect to and send requests to multiple backends based on a specific distribution algorithm and while this is natively supported in Varnish through the "directors" VMOD, UDO has a lot more capabilities.

For example, it supports ad hoc reconfiguration, it has smart retry mechanisms, and also supports activeDNS which ensures that dynamic backends can be created.

But let's see some code:

vcl 4.1;

import udo;

backend be1 { .host = "1.1.1.1"; }
backend be2 { .host = "2.2.2.2"; }
backend be3 { .host = "3.3.3.3"; }

sub vcl_init {
new udo_dir = udo.director();
udo_dir.set_type(random);
udo_dir.add_backend(be1, weight = 1);
udo_dir.add_backend(be2, weight = 1);
udo_dir.add_backend(be3, weight = 3);
}

sub vcl_backend_fetch {
set bereq.backend = udo_dir.backend();
}


The first thing we do is import the UDO VMOD and create the backends with their host and port information and in the "vcl_init" subroutine. We need to initialize a UDO object through the "udo.director()". Function this newly created object called "udo_dir"
has a set of methods that we can call "set_type()" to assign the distribution algorithm.

In this case it's "random" but it can also be "hash" for consistent hashing or "fallback" if you want to use it in an active-passive setup.

Next up, we need to assign the predefined backends. We can also assign a weight. In this case backend 3 has a weight of 3, which means it's 3 times more likely of being selected compared to the others. Finally in "vcl_backend_fetch" we can assign the selected backend by calling "udo_dir.backend()" and assigning that value to "bereq.backend".


So far there isn't a lot of difference between what UDO supports and what Varnish does natively through the directors VMOD. However, on a per-request basis we can change the distribution type, for example, from "random" to "hash" if the request has a URL that starts with "/video" and finally we'll briefly touch on dynamic backends.

vcl 4.1;

import udo;

backend be1 { .host = "1.1.1.1"; }
backend be2 { .host = "2.2.2.2"; }
backend be3 { .host = "3.3.3.3"; }

sub vcl_init {
new udo_dir = udo.director();
udo_dir.set_type(random);
udo_dir.add_backend(be1, weight = 1);
udo_dir.add_backend(be2, weight = 1);
udo_dir.add_backend(be3, weight = 3);
}

sub vcl_backend_fetch {
set bereq.backend = udo_dir.backend();
if (bereq.url ~ "^/video/") {
udo_dir.set_type(hash);
}

}


For that we need yet another Varnish Enterprise VMOD Called "activeDNS".

vcl 4.1;

import udo;
import activedns;

sub vcl_init {
new group = activedns.dns_group();
group.set_host("example.com");

new udo_dir = udo.director();
udo_dir.set_type(random);
udo_dir.subscribe(group.get_tag());
}


This allows you to do on-the-fly DNS resolution of a specific hostname and is capable of creating backends based on the results UDO can subscribe to that information and resolve the hostname at regular intervals. The hostname can return a single IP but also multiple IPs
and based on that output UDO will perform the right load balancing.


That was it for this week UDO is a very powerful VMOD and is the foundation of all things load balancing in Varnish Enterprise.


A lot of future development will go into that and make it even more efficient. But we can't deny the fact that the combination between UDO and activeDNS for dynamic backends is an interesting one. As a matter of fact that's the topic of next week's 2-Minute Tech Tuesday.

So see you next week for more about activeDNS!

 

varnish_6_by_example_download

Topics: load balancing, varnish enterprise, 2MTT, UDO

5/24/22 10:34 AM by Thijs Feryn

All things Varnish related

The Varnish blog is where the our team writes about all things related to Varnish Cache and Varnish Software...or simply vents.

SUBSCRIBE TO OUR BLOG

Recent Posts

Posts by Topic

see all