What does the Hash Consistency option do in hash-based algorithms?
Short answer
Hash Consistency is the switch that appears in the LB Algorithm box when a self-persistent algorithm (Source, URI, URL Param, HDR on HTTP; RDP Cookie on L7 TCP) is selected, and it comes off by default. When it is turned on, TR7 uses consistent hashing: when the number of running servers changes, only a small portion of the clients change place and no Backend Service receives more than 1.5 times the average load; if the limit is exceeded, the request goes to the next server.
How Does It Work?
| Hash consistency off (default) | Hash consistency on | |
|---|---|---|
| Mapping | The hash of the value is mapped to a server according to the total Weight of the running servers; the distribution is uniform | The servers are placed on a ring; the value is mapped to the nearest server on the ring |
| When a server leaves | The calculation changes; most values shift to another server | Only the values of that server are moved to the other servers |
| When a server is added | Most values shift to another server | A small portion of the values move to the new server |
| Load limit | None; a heavy value can overload a single server | A server receives at most 1.5 times the average concurrent load of the servers; if the limit is exceeded, the request goes to the next server on the ring |
| Weight | Applied | Applied |
The cost: when the load limit is exceeded, some clients go to another server instead of the server their hash points to; that is, persistence is relaxed for those requests.
When Is It Turned On?
- If a small number of values carry most of the traffic (e.g. a large tenant, an organization behind NAT).
- If servers are frequently added and removed, or frequently fail the health check and come back, and clients changing place is not wanted.
In TR7
- Visibility condition: vService → Details → the LB Algorithm box is checked and an algorithm marked "(Self-persistent)" is selected from the Algorithm list; the Hash Consistency switch appears below the algorithm-specific fields. While an algorithm that is not self-persistent or a Network vService is selected, this switch does not appear.
- Default: Off.
- Saving: It is saved with Save. In a cluster setup, the change is also sent to the peer device with the default auto-sync; if Manual Sync Mode is on, it is sent manually with Synchronize.
- Monitoring: If the switch is on, the line "Hash consistency is on" and below it the description "Prevents overload of backend services due to hash algorithm persistency" appear in the LB Algorithm section of the Load Balancer Management screen of the vService.
Common Misconceptions
- "Hash consistency makes persistence definite." On the contrary, when the load limit is exceeded, it shifts some clients to another server.
- "It appears with every algorithm." It appears only with self-persistent algorithms.
- "It is the same as Persistence → Hash." Persistence → Hash is a separate persistence method that keeps the mapping in a table and is used with algorithms that are not self-persistent; Hash consistency, on the other hand, changes how self-persistent algorithms map the hash to the servers.
How it is done in the documentation
