1.3. 请求平衡
热备份 Java 客户端将请求平衡到 Data Grid Server 集群,以便读写操作分散到节点间。
使用 BASIC 或 TOPOLOGY_AWARE 智能的客户端使用所有请求的请求平衡。使用 HASH_DISTRIBUTION_AWARE 智能将请求直接发送到存储所需密钥的节点的客户端。如果节点没有响应,客户端会回退到请求平衡。
默认平衡策略是循环的,因此 Hot Rod 客户端执行请求平衡,例如: s1、s2、s3 是 Data Grid 集群中的节点:
自定义平衡策略
如果您在 Hot Rod 客户端配置中添加类,您可以使用自定义 FailoverRequestBalancingStrategy 实现。
ConfigurationBuilder
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addServer()
.host("127.0.0.1")
.port(11222)
.balancingStrategy(new MyCustomBalancingStrategy());
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addServer()
.host("127.0.0.1")
.port(11222)
.balancingStrategy(new MyCustomBalancingStrategy());
hotrod-client.properties
infinispan.client.hotrod.request_balancing_strategy=my.package.MyCustomBalancingStrategy
infinispan.client.hotrod.request_balancing_strategy=my.package.MyCustomBalancingStrategy