Background
URL Hashing is a load-balancing method typically used in situations where load-balanced servers serve content that is mostly (but not necessarily) unique per server. It is used, for example, in a deployment where a pool of cache servers responds to requests for content.
When the NetScaler is configured to use the URL hash method, it selects a service based on the hashed value of an incoming HTTP URL. The NetScaler caches the hashed value of the URL, and subsequent requests that use the same URL make a cache hit and are forwarded to the same service. By default, the NetScaler calculates the hash value based on the first 80 bytes of the URL. You must specify the Hash Length parameter to calculate a different URL value. If the NetScaler cannot accurately parse the incoming request, it uses the round robin method for load balancing.
The two questions typically asked about this topic are:
What part of the incoming request is looked at in order for the NetScaler to determine the hash value?
How does the NetScaler select the target service?
For addressing these two questions, consider a scenario where a client is making a request to the following URL:
http://www.domain.com/path/to/content.html?query1=value1&query2=value2
The NetScaler looks at the URL up to the first 80 bytes to calculate the hash value; so in the above request, it uses the entire URL, including the query string:
/path/to/content.html?query1=value1&query2=value2
The proprietary hashing algorithm converts the above URL into a 32-bit integer, which the NetScaler performs a Mod operation against the number of bound services. For example, if there are 5 services bound and the hash value is 1097, then 1097 Mod 5 results in a value of 2, so the NetScaler selects the third bound service.
Note: The first bound service would be selected if the Mod operation gives a value of 0.
If the selected service is in a DOWN state, the NetScaler performs a Mod operation against the number of active services, producing a new Mod value that selects a service from the active service list.
If long URLs are used where only a small number of characters are different, it is a good idea to make the hash length as high as possible to try to ensure a more even load distribution. This value is 80 bytes by default, and can be changed using the following CLI command:
set lb vserver <name> lbMethod URLHASH -hashLength <positive_integer>
The hash length can be from 1 to 4096 bytes.
For more information refer to Citrix eDocs - About Hashing Methods.