baerwang commented on PR #554:
URL: https://github.com/apache/dubbo-go-pixiu/pull/554#issuecomment-1498494746
分配好像不均衡,result `map[1:6 2:2 3:4 4:5 5:3]`
```go
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, 20)
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)
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]