You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "baerwang (via GitHub)" <gi...@apache.org> on 2023/04/06 05:01:43 UTC

[GitHub] [dubbo-go-pixiu] baerwang commented on pull request #554: Add Maglev hashing LB algorithm

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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org