Hot data results in unbalanced load with ConsistentHashLoadBalance
- [x] I have searched the issues of this repository and believe that this is not a duplicate.
- [x] I have checked the FAQ of this repository and believe that this is not a duplicate.
Environment
- Dubbo version: 2.7.1
- Operating System version: CentOS 7.5
- Java version: JAVA 1.8.0_202
Issue description
ConsistentHashLoadBalance is very good at guaranteeing a robust data locality, when the same method with the same parameter is directed to always the same target (when system state does not change).
However, it is possible in reality when there exists a hot parameter, which is called significantly more frequently with the given method compared to other parameters.
This lead to a unbalanced load as the request to this method with the hot parameter is always directed to the same target, makes this target overloaded.
Expectation
Would it be possible to improve the current ConsistentHashLoadBalance implementation to better balance the load under this edge case?
good suggestion, we should consider the hotspot issue.
I will send a pr to enhance the design of the ConsistentHashLoadBalancer
A new algorithms "Consistent Hashing with Bounded Loads"introduced by Vahab Mirrokni (work at Google Research) in 2018 can resolve this problem.
Brief introduction quoted from a blog which use this new algorithm and works well (https://medium.com/vimeo-engineering-blog/improving-load-balancing-with-a-new-consistent-hashing-algorithm-9f1bd75709ed):
Here is a simplified sketch of the algorithm. Some details are left out, and if you intend to implement it yourself, you should definitely go to the original paper for information. First, define a balancing factor, c, which is greater than 1. c controls how much imbalance is allowed between the servers. For example, if c = 1.25, no server should get more than 125% of the average load. In the limit as c increases to ∞, the algorithm becomes equivalent to plain consistent hashing, without balancing; as c decreases to near 1 it becomes more like a least-connection policy and the hash becomes less important. In my experience, values between 1.25 and 2 are good for practical use. When a request arrives, compute the average load (the number of outstanding requests, m, including the one that just arrived, divided by the number of available servers, n). Multiply the average load by c to get a “target load”, t. In the original paper, capacities are assigned to servers so that each server gets a capacity of either ⌊t⌋ or ⌈t⌉, and the total capacity is ⌈cm⌉. Therefore the maximum capacity of a server is ⌈cm/n⌉, which is greater than c times the average load by less than 1 request. To support giving servers different “weights”, as HAProxy does, the algorithm has to change slightly, but the spirit is the same — no server can exceed its fair share of the load by more than 1 request. To dispatch a request, compute its hash and the nearest server, as usual. If that server is below its capacity, then assign the request to that server. Otherwise, go to the next server in the hash ring and check its capacity, continuing until you find a server that has capacity remaining. There has to be one, since the highest capacity is above the average load, and it’s impossible for every server’s load to be above average. This guarantees some nice things: No server is allowed to get overloaded by more than a factor of c plus 1 request. The distribution of requests is the same as consistent hashing as long as servers aren’t overloaded. If a server is overloaded, the list of fallback servers chosen will be the same for the same request hash — i.e. the same server will consistently be the “second choice” for a popular piece of content. This is good for caching. If a server is overloaded, the list of fallback servers will usually be different for different request hashes — i.e. the overloaded server’s spillover load will be distributed among the available servers, instead of all landing on a single server. This depends on each server being assigned multiple points in the consistent hash ring.
@beiwei30 Please help me review the above PR.
I will submit a new pr this weekend.