-
Notifications
You must be signed in to change notification settings - Fork 953
feat: Add maglev consistent hashing #2831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
feat: Add maglev consistent hashing #2831
Conversation
goos: darwin
goarch: amd64
pkg: dubbo.apache.org/dubbo-go/v3/cluster/loadbalance
cpu: VirtualApple @ 2.50GHz
BenchmarkRoudrobinLoadbalance-8 7713 157304 ns/op 88116 B/op 2555 allocs/op
BenchmarkLeastativeLoadbalance-8 7767 148902 ns/op 81886 B/op 2043 allocs/op
BenchmarkConsistenthashingLoadbalance-8 59444 20656 ns/op 3440 B/op 267 allocs/op
BenchmarkP2CLoadbalance-8 2774712 441.4 ns/op 472 B/op 10 allocs/op
BenchmarkInterleavedWeightedRoundRobinLoadbalance-8 22604 52958 ns/op 45312 B/op 1027 allocs/op
BenchmarkRandomLoadbalance-8 24267 47699 ns/op 38992 B/op 767 allocs/op
BenchmarkAliasMethodLoadbalance-8 24961 47120 ns/op 49232 B/op 772 allocs/op
BenchmarkMaglevConsistentHashingLoadBalance-8 8415 127673 ns/op 598406 B/op 262 allocs/op
PASS
ok dubbo.apache.org/dubbo-go/v3/cluster/loadbalance 14.628s |
From the benchmark results alone, the performance of maglev does not seem very good. |
c8cc99b
to
1a125e1
Compare
Thanks @marsevilspirit BTW, I will optimize this algorithm implementation |
1a125e1
to
23ecde6
Compare
|
Signed-off-by: dongjiang <[email protected]>
Signed-off-by: dongjiang <[email protected]>
Signed-off-by: dongjiang <[email protected]>
4aa4ee9
to
27e29ac
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some minor comments.
return m | ||
} | ||
|
||
// buildLookupTable 构建 Maglev 查找表 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, why are the annotations in Chinese used here, and other places contain English annotations? Can they all be unified into English annotations?
} | ||
} | ||
|
||
// generatePermutations 生成每个节点的排列 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
return permutations | ||
} | ||
|
||
// calculatePermutation 计算单个节点的排列 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
return xxhash.Sum64String(s) | ||
} | ||
|
||
// isPrime 函数用于判断一个数是否为素数 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
return true | ||
} | ||
|
||
// NextPrime 函数用于找出比 n 大的第一个素数 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
ref: https://static.googleusercontent.com/media/research.google.com/zh-CN//pubs/archive/44824.pdf