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:
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.
For that we need yet another Varnish Enterprise VMOD Called "activeDNS".
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!