-
Notifications
You must be signed in to change notification settings - Fork 154
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
Add Maglev hashing LB algorithm #554
Conversation
shawnh2
commented
Mar 30, 2023
- add Maglev hash load balancing algorithm
- rename original consistent hash to ring-hash
Codecov Report
@@ Coverage Diff @@
## develop #554 +/- ##
===========================================
+ Coverage 54.71% 54.75% +0.04%
===========================================
Files 667 669 +2
Lines 78143 78323 +180
===========================================
+ Hits 42756 42886 +130
- Misses 31733 31778 +45
- Partials 3654 3659 +5
... and 19 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
分配好像不均衡,result func TestMaglevHash(t *testing.T) {
nodeCount := 5
nodes := make([]*model.Endpoint, 0, nodeCount)
for i := 1; i <= nodeCount; i++ {
name := strconv.Itoa(i)
nodes = append(nodes, &model.Endpoint{ID: name, Name: name,
Address: model.SocketAddress{Address: "192.168.1." + name, Port: 1000 + i}})
}
cluster := &model.ClusterConfig{
Name: "test-cluster",
Endpoints: nodes,
LbStr: model.LoadBalanceMaglevHashing,
ConsistentHash: model.ConsistentHash{ReplicaFactor: 10},
}
cluster.CreateConsistentHash()
var (
hashing = MaglevHash{}
path string
)
record := make(map[string]int, nodeCount)
for i := 1; i <= 20; i++ {
path = fmt.Sprintf("/pixiu?total=%d", i)
handler := hashing.Handler(cluster, &http.HttpContext{Request: &stdHttp.Request{Method: stdHttp.MethodGet, RequestURI: path}})
if _, ok := record[handler.ID]; ok {
record[handler.ID]++
continue
}
record[handler.ID] = 1
}
t.Log(record)
} |
maglev hash 算法要求的是 LookUpTable 的表长度(也就是其结构体内 size 字段的值)必须是个质数,这样可以保证均衡。 但在目前的实现中,这一点我没有去保证,我来补充一下。 |
fixed, @baerwang PTAL |
Using a simple benchmark testing tool https://github.com/mark4z/hey to test the effect of load balancing, 1 of 5 endpoints always can not receive requests, and starts to get 503 frequently after a period of time. |
---
static_resources:
listeners:
- name: "net/http"
protocol_type: "HTTP"
address:
socket_address:
address: "0.0.0.0"
port: 8888
filter_chains:
filters:
- name: dgp.filter.httpconnectionmanager
config:
route_config:
routes:
- match:
prefix: "/count"
route:
cluster: "count"
cluster_not_found_response_code: 505
http_filters:
- name: dgp.filter.http.httpproxy
config:
config:
idle_timeout: 5s
read_timeout: 5s
write_timeout: 5s
clusters:
- name: "count"
lb_policy: "MaglevHashing"
endpoints:
- id: 1
socket_address:
address: localhost
port: 8080
- id: 2
socket_address:
address: localhost
port: 8081
- id: 3
socket_address:
address: localhost
port: 8082
- id: 4
socket_address:
address: localhost
port: 8083
- id: 5
socket_address:
address: localhost
port: 8084
shutdown_config:
timeout: "60s"
step_timeout: "10s"
reject_policy: "immediacy" |
此次测试,由于该版代码并没有在 pluginregistry 中注册,所以压测的实质上是默认的 rand 策略。至于为什么总有一个节点接收不到请求,我看了一下是 rand 的随机区间设置的有问题,目前已更正。 |
new benchmark result on Maglev hash, using same config as #554 (comment) endpoints 1 recv: 5847 |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
nice job |