当前位置:网站首页>Redis缓存负载均衡使用的一致性哈希算法
Redis缓存负载均衡使用的一致性哈希算法
2022-04-22 05:33:00 【commonBean】
原文链接
由于普通哈希算法实现的缓存负载均衡存在扩展能力和容错能力差问题,所以我们引入一致性哈希算法。
一句话概括一致性哈希:就是普通取模哈希算法的改良版,哈希函数计算方法不变,只不过是通过构建环状的 Hash 空间代替普通的线性 Hash 空间。
操作
- 选择一个足够大的Hash空间(一般是 0 ~ 2^32)构成一个哈希环。
- 对于缓存集群内的每个存储服务器节点计算 Hash 值,就是服务节点在 Hash 环上的位置。
- 对每个需要存储的数据 key 同样也计算一次哈希值,计算之后的哈希也映射到环上
优点:
- 扩展能力提升
当需要增加节点时,受影响的只有下一个节点的部分数据,将数据迁移到新节点即可。 - 容错能力提升
节点失效时,受影响的只有当前节点,不会对其他节点数据造成影响,只需要将该节点数据存到按顺时钟方向的下一个节点即可。
存在的问题:
- 数据倾斜
节点经过哈希算法后分布不均匀,导致数据大量存储在某一个节点上 - 节点雪崩
1,由于数据倾斜导致节点请求压力过大挂掉
2,由于某些原因节点宕机,导致该节点的数据全部打到下一节点上,下一节点由于请求过大挂掉
3,基于以上原因节点挂掉后,数据又打到下一节点,下一节点同样由于压力过大挂掉。。。导致全部节点挂掉,造成节点雪崩
解决方案
如何解决数据倾斜和节点雪崩呢?
- 虚拟节点
就是对原来单一的物理节点在哈希环上虚拟出几个它的分身节点,这些分身节点称为「虚拟节点」。打到分身节点上的数据实际上也是映射到分身对应的物理节点上,这样一个物理节点可以通过虚拟节点的方式均匀分散在哈希环的各个部分,解决了数据倾斜问题。
版权声明
本文为[commonBean]所创,转载请带上原文链接,感谢
https://blog.csdn.net/u011357213/article/details/112697721
边栏推荐
猜你喜欢

C language version: establishment and basic operation of chain team

Online Tetris with automatic hang-up source code

MySQL事务

Force buckle - 300 Longest increasing subsequence

Configure security policy on ENSP

枚舉和Lambda錶達式

The unreal engine uses loadclass to load the blueprint class

MySQL 第6章 Navicat 的安装与使用

【FedMD,一种利用模型蒸馏的异构FL训练方法】FedMD: Heterogenous Federated Learning via Model Distillation

Dolphin DB vscode plug-in tutorial
随机推荐
I/O基础知识入门
Application of C language stack: binary conversion
C language version: the establishment and basic operation of chain stack
Kaggle_NBME NLP比赛Baseline详解(2)
Simulate the infectious disease model with MATLAB (only do matlab simulation learning and practice, not actual situation and application)
Force buckle - 300 Longest increasing subsequence
GBase 8s V8. 8 SQL Guide: tutorial-5.3
遇见DOM
C language version: the pre order, middle order and post order non recursive traversal of binary tree
Use render texture to display 3D model animation on the UI
2022.4.21-----leetcode. eight hundred and twenty-four
Hloj 1936 covered with squares
2.words平均长度
OBDUMPER常用导出命令
Unreal engine sequence effect and audio binding trigger
MySQL高级查询
The MySQL table removes duplicate values and keeps only one
Method for coexistence of Keil-C51 and keil arm
Spark 之 unsafeRow
MySQL表约束和表设计