Home > Sysadmin > varnish: Send a client always on the same backend

varnish: Send a client always on the same backend

I’m now very close to migrate from akamai to varnish at work. However, since we doesn’t have session replications on the application server, I was required to send a client always on the same backend, even if the user is not authentified. In a first try, we thought about use a cookie, valued by the name of the server, and write some VCL to define the backend based on the cookie value.

However, thanks to the varnish developper (through the channel) phk pointed me they’re working on a director method to implements this behavior. While this feature is not yet available on a release, it’s present in the trunk (I’m using r4602).

Here the source code:

if (vs->criteria == c_client) {
/*
* Hash the client IP# ascii representation, rather than
* rely on the raw IP# being a good hash distributor, since
* experience shows this not to be the case.
* We do not hash the port number, to make everybody behind
* a given NAT gateway fetch from the same backend.
*/
SHA256_Init(&ctx);
AN(sp->addr);
SHA256_Update(&ctx, sp->addr, strlen(sp->addr));
SHA256_Final(sign, &ctx);
hp = sign;
}

Here how to define your director:

director rtl client {
{ .backend = www1rtl; .weight = 1; }
{ .backend = www2rtl; .weight = 1; }
}

Categories: Sysadmin Tags:
  1. No comments yet.
  1. No trackbacks yet.