Skip to content

Using multiple node support and load balancing policy in Kundera

Vivek Mishra edited this page Jun 23, 2013 · 9 revisions

Multiple node support and configuring load balancing policies are now supported within Kundera(Cassandra only). Please refer here for more details.Multiple node support can be used as:

Multiple nodes on same port

In case all Cassandra nodes are running on same port(say 9160). So minimal required configuration is:

<property name="kundera.nodes" value="192.168.120.134,192.168.120.111,192.168.120.121,192.168.120.141" />
<property name="kundera.port" value="9160" />

in persistence.xml.

To configure load balancer for available set of properties(see Load balancing specific properties section), you need to create an external file say(KunderaNodeConfig.xml) as:

<?xml version="1.0" encoding="UTF-8"?>
<clientProperties>
  <datastores>
   <dataStore>
	<name>cassandra</name>
	<connection>
  	 <servers>
        </servers>
     <!-- Load balancing specific configuration -->
    <properties>
	<property name="loadbalancing.policy" value="roundrobin"></property>
        <property name="retry" value="true"></property>
        <property name="retry.delay" value="1"></property>
        <property name="max.wait" value="3000"></property> 
    </properties>
 </connection>
</dataStore>
</datastores>
</clientProperties>

Multiple nodes with different port

In case different Cassandra nodes are running on different ports, it is required to map such configurations in form of "external file" configuration as(say KunderaNodeConfig.xml):

<?xml version="1.0" encoding="UTF-8"?>
<clientProperties>
  <datastores>
   <dataStore>
	<name>cassandra</name>
	<connection>
  	 <servers>
	  <server>
	   <host>192.168.120.134</host>
	   <port>9160</port>
	   <properties>
	    <property name="testonborrow" value="true"></property>
	    <property name="testwhileidle" value="true"></property>
    	    <property name="testonconnect" value="true"></property>
	    <property name="testonreturn" value="true"></property>
	    <property name="socket.timeout" value="120000"></property>
	    <property name="failover.policy" value="on.fail.try.one.next.available"></property>
	    <property name="retry" value="true"></property>
	    <property name="kundera.pool.size.max.active" value="31"></property>
 	 </properties>
	</server>

	<server>
	  <host>192.168.120.111</host>
	  <port>9161</port>
  	  <properties>
	     <property name="testonborrow" value="true"></property>
	     <property name="testwhileidle" value="true"></property>
	     <property name="testonconnect" value="true"></property>
	     <property name="testonreturn" value="true"></property>
	     <property name="socket.timeout" value="120000"></property>
	     <property name="failover.policy" value="on.fail.try.one.next.available"></property>
	     <property name="retry" value="true"></property>
	     <property name="kundera.pool.size.max.active" value="33"></property>
	 </properties>
       </server>
    </servers>
     <!-- Load balancing specific configuration -->
    <properties>
	<property name="loadbalancing.policy" value="roundrobin"></property>
        <property name="retry" value="true"></property>
        <property name="retry.delay" value="1"></property>
        <property name="max.wait" value="3000"></property> 
    </properties>
 </connection>
</dataStore>
</datastores>
</clientProperties>

Next step is to map such external configuration file(KunderaLoadConfig.xml) within persistence.xml as:

<property name="kundera.client.property" value="KunderaLoadConfig.xml" /> 

Managing Load balancing policy

Load balancing specific configuration can be defined within external configuration file as:

 <properties>
	<property name="loadbalancing.policy" value="roundrobin"></property>
        <property name="retry.delay" value="1"></property>
    </properties>

Load balancing specific properties

Available set of properties for load balancing are:

Property Value
failover.policy on.fail.try.all.available,on.fail.try.one.next.available,fail.fast
retry true/false
loadbalancing.policy roundrobin,leastactive
testonborrow true/false
testonreturn true/false
testonconnect true/false
testwhileidle true/false
socket.timeout Socket time out(in seconds)
kundera.pool.size.max.active Maximum active number of connection in pool.
retry.delay retry delay(in seconds)
max.wait wait time in case all active connections are busy(in mili seconds)
Clone this wiki locally