README ¶ Google Maglev Hash 算法的 Go 实现 Maglev是什么? 在分布式系统中做负载均衡用,一致性哈希算法。 maglev有如下特点: 1、流量均匀分配 2、连接一致性(同一连接的数据包会被转发到相同的服务器) 3、对小数据包有高吞吐能力 论文地址 使用的三方库: siphash,sipHash通过让输出随机化,减少 Hash Flooding 攻击 总结: 1、首先哈希表的数量m 必须是素数 2、可以与之前的 consistent 项目对照着看 参考资料: https://manjusaka.itscoder.com/posts/2020/05/23/a-simple-introduction-about-maglev/ https://tech.meituan.com/2017/01/05/mgw.html https://www.youtube.com/watch?v=_GRM1Ij_3t0 https://www.youtube.com/watch?v=jk6oiBJxcaA https://writings.sh/post/consistent-hashing-algorithms-part-4-maglev-consistent-hash https://www.jianshu.com/p/9a9b269e68f7 Expand ▾ Collapse ▴ Documentation ¶ Index ¶ type Maglev func NewMaglev(backends []string, m uint64) (*Maglev, error) func (m *Maglev) Add(backend string) error func (m *Maglev) Clear() func (m *Maglev) Get(client string) (string, error) func (m *Maglev) Remove(backend string) error func (m *Maglev) Set(backends []string) error Constants ¶ This section is empty. Variables ¶ This section is empty. Functions ¶ This section is empty. Types ¶ type Maglev ¶ type Maglev struct { // contains filtered or unexported fields } Maglev 结构体,类似Java里Maglev的类 func NewMaglev ¶ func NewMaglev(backends []string, m uint64) (*Maglev, error) NewMaglev 类似 Java里的构造函数,参数是后端服务器名称列表,还有哈希表大小m func (*Maglev) Add ¶ func (m *Maglev) Add(backend string) error Add 新增一个后台服务器 func (*Maglev) Clear ¶ func (m *Maglev) Clear() Clear 清空表 func (*Maglev) Get ¶ func (m *Maglev) Get(client string) (string, error) Get 给一个客户端,获取它对应的后台服务器 func (*Maglev) Remove ¶ func (m *Maglev) Remove(backend string) error Remove 删除一个后台服务器 func (*Maglev) Set ¶ func (m *Maglev) Set(backends []string) error Set 设置后端服务器,参数:后端服务器列表 Source Files ¶ View all Source files maglev.go Click to show internal directories. Click to hide internal directories.