6 Star 11 Fork 1

distill/distill-infra

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
lb_hash.go 441 Bytes
一键复制 编辑 原始数据 按行查看 历史
Lyndon Hu 提交于 5年前 . infra init
package lb
import (
"hash/crc32"
)
//基于Hash算法的负载均衡器
var _ Balancer = new(HashBalancer)
type HashBalancer struct {
}
func (h *HashBalancer) Next(key string, hosts []*ServerInstance) *ServerInstance {
if len(hosts) == 0 {
return nil
}
//hash
count := crc32.ChecksumIEEE([]byte(key))
//取模计算索引
index := int(count) % len(hosts)
//按照索引取出实例
instance := hosts[index]
return instance
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/banyanhouse/distill-infra.git
git@gitee.com:banyanhouse/distill-infra.git
banyanhouse
distill-infra
distill-infra
v0.0.16-grpc-t2

搜索帮助