gpt4 book ai didi

load-balancing - 当循环可以均匀地分配流量时,为什么我们需要一致的散列

转载 作者:行者123 更新时间:2023-12-03 18:44:42 24 4
gpt4 key购买 nike

当负载均衡器可以使用循环算法将传入的请求平均分配给节点时,为什么我们需要使用一致性哈希来分配负载?使用一致散列和 RR 分配负载的最佳方案是什么?

最佳答案

this blog

With traditional “modulo hashing”, you simply consider the requesthash as a very large number. If you take that number modulo the numberof available servers, you get the index of the server to use. It’ssimple, and it works well as long as the list of servers is stable.But when servers are added or removed, a problem arises: the majorityof requests will hash to a different server than they did before. Ifyou have nine servers and you add a tenth, only one-tenth of requestswill (by luck) hash to the same server as they did before. Consistent hashing can achieve well-distributed uniformity.

Thenthere’s consistent hashing. Consistent hashing uses a more elaboratescheme, where each server is assigned multiple hash values based onits name or ID, and each request is assigned to the server with the“nearest” hash value. The benefit of this added complexity is thatwhen a server is added or removed, most requests will map to the sameserver that they did before. So if you have nine servers and add atenth, about 1/10 of requests will have hashes that fall near thenewly-added server’s hashes, and the other 9/10 will have the samenearest server that they did before. Much better! So consistenthashing lets us add and remove servers without completely disturbingthe set of cached items that each server holds.


同理,round-robin算法用于服务器列表稳定,LB流量随机的场景。一致性散列用于后端服务器需要向外扩展或缩减的场景,并且大多数请求将映射到它们之前所做的同一台服务器。一致性哈希可以实现良好分布的一致性。

关于load-balancing - 当循环可以均匀地分配流量时,为什么我们需要一致的散列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58361938/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com