Round robin vs. consistent hash in distribution mode
tuxx1337 Feb 8, 2012 11:21 AMHi,
I have the following configuration file used by 2 Infinispan Hotrod servers:
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd" xmlns="urn:infinispan:config:5.1"> <global> <transport> <properties> <property name="configurationFile" value="jgroups.xml"/> </properties> </transport> </global> <namedCache name="cache1"> <clustering mode="distribution"> <sync/> <hash numOwners="1"/> </clustering> </namedCache> <namedCache name="cache2"> <clustering mode="distribution"> <sync/> <hash numOwners="1"/> </clustering> </namedCache> </infinispan>
So, as it can be seen, I want to use these two distributed caches in a Hotrod cluster of servers. Therefore:
./startServer.sh -r hotrod -c infinispan.xml -l 127.0.0.1 -p 11222 ./startServer.sh -r hotrod -c infinispan.xml -l 127.0.0.1 -p 11223
And then I start the client using the following properties:
Properties properties = new Properties(); properties.put("infinispan.client.hotrod.server_list", "127.0.0.1:11222"); properties.put("infinispan.client.hotrod.hash_function_impl.2", "org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV2"); RemoteCacheManager cacheManager = new RemoteCacheManager(properties);
However, Infinispan is using RoundRobinBalancingStrategy for choosing a server when doing a client request:
TRACE [pool-4-thread-1] (ConsistentHashFactory.java:63) - Processing consistent hash: infinispan.client.hotrod.hash_function_impl.2 TRACE [pool-4-thread-1] (ConsistentHashFactory.java:69) - Added consistent hash version 2: org.infinispan.client.hotrod.impl.consistenthash.ConsistentHashV2 ... DEBUG [pool-4-thread-1] (TcpTransportFactory.java:90) - Load balancer class: org.infinispan.client.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy ... TRACE [pool-4-thread-1] (Codec11.java:62) - Not using a consistent hash function (hash function version == 0)
Therefore, instead of the client using the hash function to compute the server node, it chooses it based on a round robin approach, resulting in many useless hops in the network.
My question is: how do I correctly configure topology aware clients which use consistent hashing to select servers in the cluster and to directly send the request to?
Thanks.
EDIT: Using Infinispan-5.1.0-FINAL