Re: how to achieve URL hash LB algorithm on ZXTM

Ben Mansell <[email protected]> Wed, 29 Jul 2009 10:19:38 +0100
Newsgroups gmane.comp.programming.load-balancing.general
Message-ID <[email protected]>
On 29/07/2009 00:48, Eric Y. Zhang wrote:
> routing requests to different backend server in same pool.let's say, I have 5 squid servers behind LB, if LB can do URL hash, then 1of squid server only needs take 20% requests, that helps a lot.

There are a few ways to achieve this. The first is to use the 'perceptive' 
load balancing algorithm. This takes several factors into account when 
choosing a node to use, including the URL of a request. However, it's only 
one of many factors, so it doesn't rigidly enforce the URL->squid server 
mapping that you probably want.

What you can do instead is to leave the LB algorithm unaltered, and 
instead use a session persistence class to dictate where each request goes.

Create a 'Universal' session persistence class and assign it to your pool 
of squid servers. This then lets a TrafficScript rule pick which squid 
server to use. The TrafficScript command is:

connection.setPersistenceKey( http.getRawURL() );

...and then requests with the same URL will use the same squid server. 
However, this needs a bit of refinement. You are likely to have many many 
different URLs going to your squid servers. Each different URL creates a 
different session persistence mapping, and there are limits on the number 
of these. To ensure that too many aren't used, we can 'hash' the URL into 
a smaller set of sessions:

# Hash the URL, then take the first byte, giving 256 different sessions.
# This also uses the website hostname, in case you are caching several
# websites.
$session = string.left( string.hashMD5( http.getHostHeader() .
                                         http.getRawURL() ), 1 );
connection.setPersistenceKey( $session );

So, add this rule in, assign it to your virtual server and then your squid 
traffic will be nicely divided up. This should improve the cache hit rates.

Ben
_______________________________________________
lb-l mailing list
[email protected]
http://vegan.net/mailman/listinfo/lb-l
Searchable Archive: http://vegan.net/lb/archive
http://lbdigest.com Load Balancing Digest
http://lbwiki.com Load Balancing Wiki