Click on Javadoc link to open Javadoc documentation.
Package
org.gridgain.grid.spi.loadbalancing.roundrobin Javadoc![]()
Available starting with GridGain 
Description
GridRoundRobinLoadBalancingSpi ![]()
![]()
When configured in per-task mode, implementation will pick a random starting node at the beginning of every task execution and then sequentially iterate through all nodes in topology starting from the picked node. This is the default configuration and should fit most of the use cases as it provides a fairly well-distributed split and also ensures that jobs within a single task are spread out across nodes to the maximum. For cases when split size is equal to the number of nodes, this mode guarantees that all nodes will participate in the split.
When configured in global mode, a single sequential queue of nodes is maintained for all tasks and the next node in the queue is picked every time. In this mode (unlike in per-task mode) it is possible that even if split size may be equal to the number of nodes, some jobs within the same task will be assigned to the same node if multiple tasks are executing concurrently.
Configuration
The following configuration parameters can be used to configure GridRoundRobinLoadBalancingSpi ![]()
| Setter Method | Description | Optional | Default |
|---|---|---|---|
| setPerTask(boolean) |
Configuration parameter indicating whether a new round robin order should be created for every task. If true then load balancer is guaranteed to iterate through nodes sequentially for every task - so as long as number of jobs is less than or equal to the number of nodes, jobs are guaranteed to be assigned to unique nodes. If false then one round-robin order will be maintained for all tasks, so when tasks execute concurrently, it is possible for more than one job within task to be assigned to the same node. | Yes | Default is true |
Examples
As any GridGain SPI, GridRoundRobinLoadBalancingSpi ![]()
GridFifoQueueCollisionSpi colSpi = new GridFifoQueueCollisionSpi();GridRandomLoadBalancingSpi = new GridRandomLoadBalancingSpi(); // Configure SPI to use global round-robin mode. spi.setPerTask(false); GridConfigurationAdapter cfg = new GridConfigurationAdapter(); // Override default load balancing SPI. cfg.setLoadBalancingSpi(spi); // Start grid. GridFactory.start(cfg);
or from Spring configuration file
<bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfigurationAdapter" singleton="true"> ... <property name="loadBalancingSpi"> <bean class="org.gridgain.grid.spi.loadbalancing.roundrobin.GridRoundRobinLoadBalancingSpi"> <!-- Set to global round-robin mode. --> <property name="perTask" value="false"/> </bean> </property> ... </bean>

For more information about using Spring framework for configuration click here.
