0

I have 2 varnish, each of them having 2 backends (same varnish versions -v4.x- and configuration file).

Incoming client connections are randomly distributed to any available varnish.

I need clients to always use the same varnish backend, based on their source IP (except, of course, in case of a failed backend).

I use the following (simplified) configuration:

new servers = directors.hash();
servers.add_backend(srv01, 1.0);
servers.add_backend(srv02, 1.0);

sub vcl_recv {
    set req.backend_hint = servers.backend(client.ip);
}

I would like to know if the hashing algorithm used by Varnish will guarantee that no matter which Varnish they go through, clients will always be using the same backend.

It means that no random-like data must be used to initialize the hashing algorithm. Do you know if it is the case?

Totor
  • 2,916
  • 3
  • 23
  • 31

1 Answers1

0

The hash and shard directors will hash to the same backend servers, assuming the same configuration and runtime state (health of backend servers). It's using sha256 with no random component (other than the hashing key).

Tollef Fog Heen
  • 712
  • 3
  • 10
  • Thanks. Would you have a source to provide, for example to the source code part where it is possible to see the hashing process using sha256? – Totor May 31 '17 at 22:12
  • See https://github.com/varnishcache/varnish-cache/blob/master/lib/libvmod_directors/vmod_shard.c and neighbouring files. Documentation and interface is defined in https://github.com/varnishcache/varnish-cache/blob/master/lib/libvmod_directors/vmod.vcc. – Tollef Fog Heen Jun 02 '17 at 17:16