一致性哈希选址
在负载均衡阶段基于一致性哈希进行选址
特性说明
使用场景
在有多台服务端的时候根据请求参数的进行一致性哈希散列选择服务端。
使用方式
配置一致性哈希的方式有很多,最常见的是:
注解配置
@DubboReference(loadbalance = “consistenthash”)
API 配置
referenceConfig.setLoadBalance(“consistenthash”);
Properties 配置
dubbo.reference.loadbalance=consistenthash
XML 配置
<dubbo:reference loadbalance=“consistenthash” />
默认采用第一个参数作为哈希 key,如果需要切换参数,可以指定 hash.arguments
属性
ReferenceConfig<DemoService> referenceConfig = new ReferenceConfig<DemoService>();
// ... init
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("hash.arguments", "1");
parameters.put("sayHello.hash.arguments", "0,1");
referenceConfig.setParameters(parameters);
referenceConfig.setLoadBalance("consistenthash");
referenceConfig.get();
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.
最后修改 August 24, 2022: [majorization] 一致性哈希选址 (#1409) (6aa964ba5)