Click on Javadoc link to open Javadoc documentation.
Package
org.gridgain.grid.spi.loadbalancing.adaptive Javadoc![]()
Available starting with GridGain 
Description
GridAdaptiveLoadBalancingSpi ![]()
Adaptive Node Probes
This SPI comes with pluggable algorithm to calculate a node load at any given point of time. The algorithm is defined by pluggable GridAdaptiveLoadProbe ![]()
![]()
Note that if GridAdaptiveLoadProbe.getLoad(org.gridgain.grid.GridNode, int) ![]()
When working with node metrics, take into account that all averages are calculated over metrics history size defined by GridConfiguration.getMetricsExpireTime() ![]()
![]()
You should also keep in mind that metrics for remote nodes are delayed (usually by the heartbeat frequency). So if it is acceptable in your environment, set the heartbeat frequency to be more inline with job execution time. Generally, the more often heartbeats between nodes are exchanged, the more precise the metrics are. However, you should keep in mind that if heartbeats are exchanged too often then it may create unnecessary traffic in the network. Heartbeats (or metrics update frequency) can be configured via underlying Discovery SPI used in your grid.
Here is an example of how probing can be implemented to use number of active and waiting jobs as probing mechanism:
public class FooBarLoadProbe implements GridAdaptiveLoadProbe { // Flag indicating whether to use average value or current. private int useAvg = true; public FooBarLoadProbe(boolean useAvg) { this.useAvg = useAvg; } // Calculate load based on number of active and waiting jobs. public double getLoad(GridNode node, int jobsSentSinceLastUpdate) { GridNodeMetrics metrics = node.getMetrics(); if (useAvg == true) { double load = metrics.getAverageActiveJobs() + metrics.getAverageWaitingJobs(); if (load > 0) { return load; } } return metrics.getCurrentActiveJobs() + metrics.getCurrentWaitingJobs(); } }
Which Node Probe To Use
There is no correct answer here. Every single node probe will work better or worse in different environments. CPU load probe (default option) is the safest approach to start with as it simply attempts to utilize every CPU on the grid to the maximum. However, you should experiment with other probes by executing load tests in your environment and observing which probe gives you best performance and load balancing.
The following load probes are available with the product:
- Grid Adaptive CPU Load Probe
- Grid Adaptive Benchmark Load Probe
- Grid Adaptive Processing Time Load Probe
- Grid Adaptive Job Count Load Probe
Grid Adaptive CPU Load Probe
GridAdaptiveCpuLoadProbe ![]()
The following configuration parameters can be used to configure GridAdaptiveCpuLoadProbe ![]()
| Setter Method | Description | Optional | Default |
|---|---|---|---|
| setUseAverage(boolean) |
Indicates whether implementation should either use average CPU load values or current. | Yes | Default value is true |
| setUseProcessors(boolean) |
Indicates whether implementation should either take number of processors on the node into account or not. Since CPU load on multi-processor boxes shows medium load of multiple CPU's it usually means that the remaining capacity is proportional to the number of CPU's (or cores) on the node. This configuration parameter indicates whether to divide each node's CPU load by the number of processors on that node. | Yes | Default value is true. |
| setProcessorCoefficient(double) |
In some environments every processor may not be adding 100% of processing power. For example, if you are using multi-core CPU's, then addition of every core would probably result in about 75% of extra CPU power. To account for that, you should set this parameter parameter to 0.75 . | Yes | Default value is 1 |
Below is an example of how CPU load probe would be configured in GridGain Spring configuration file:
<property name="loadBalancingSpi"> <bean class="org.gridgain.grid.spi.loadbalancing.adaptive.GridAdaptiveLoadBalancingSpi"> <property name="loadProbe"> <bean class="org.gridgain.grid.spi.loadbalancing.adaptive.GridAdaptiveCpuLoadProbe"> <property name="useAverage" value="true"/> <property name="useProcessors" value="true"/> <property name="processorCoefficient" value="0.9"/> </bean> </property> </bean> </property>
This probe implementation is used by default by GridAdaptiveLoadBalancingSpi SPI.
Grid Adaptive Benchmark Load Probe
GridAdaptiveBenchmarkLoadProbe ![]()
![]()
![]()
![]()
You can initialize local node benchmarks by adding/uncommenting the following section in GridGain Spring XML file:
<bean id="grid.cfg" class="org.gridgain.grid.GridConfigurationAdapter" scope="singleton"> <!-- Grid local node benchmark is a good example of a complex attribute that can be added to the node at startup. Note that you will have to use 'grid.node.benchmark' grid node attribute name to get the benchmark for the given node. --> <property name="userAttributes"> <map> <entry key="grid.node.benchmark"> <bean class="org.gridgain.grid.benchmarks.GridLocalNodeBenchmark" init-method="start"/> </entry> </map> </property> <!-- Load balancing SPI that takes node benchmarks into account. Note that you are free to configure which benchmark scores to use. The configuration below ignores I/O and trigonometry scores. --> <property name="loadBalancingSpi"> <bean class="org.gridgain.grid.spi.loadbalancing.adaptive.GridAdaptiveLoadBalancingSpi"> <property name="loadProbe"> <bean class="org.gridgain.grid.spi.loadbalancing.adaptive.GridAdaptiveBenchmarkLoadProbe"> <!-- Specify name of benchmark node attribute (the same as above). --> <property name="benchmarkAttributeName" value="grid.node.benchmark"/> <!-- Benchmarks scores to use. --> <property name="useIntegerScore" value="true"/> <property name="useLongScore" value="true"/> <property name="useDoulbeScore" value="true"/> <property name="useIoScore" value="false"/> <property name="useTrigonometryScore" value="false"/> </bean> </property> </bean> </property> </bean>
Please make sure to properly initialize this probe to use exactly the scores you need in your grid. For example, if your jobs don't do any I/O, then you probably should disable I/O score. If you are not doing any trigonometry calculations, then you should disable trigonometry score.
Also, keep in mind that the benchmark probe value are constant and do not change throughout node uptime.
Grid Adaptive Processing Time Load Probe
GridAdaptiveProcessingTimeLoadProbe ![]()
Based on {{GridAdaptiveProcessingTimeLoadProbe.setUseAverage(boolean)} ![]()
configuration parameter, this implementation will either use average job execution time values or current (default is to use averages). The algorithm returns a sum of job wait time and job execution time.
Below is an example of how CPU load probe would be configured in GridGain Spring XML configuration file:
<property name="loadBalancingSpi"> <bean class="org.gridgain.grid.spi.loadbalancing.adaptive.GridAdaptiveLoadBalancingSpi"> <property name="loadProbe"> <bean class="org.gridgain.grid.spi.loadbalancing.adaptive.GridAdaptiveProcessingTimeLoadProbe"> <property name="useAverage" value="true"/> </bean> </property> </bean> </property>
Grid Adaptive Job Count Load Probe
GridAdaptiveJobCountLoadProbe ![]()
Based on {{GridAdaptiveJobCountLoadProbe.setUseAverage(boolean)} ![]()
The load of a node is simply calculated by adding active and waiting job counts.
Below is an example of how CPU load probe would be configured in GridGain Spring configuration file:
<property name="loadBalancingSpi>;
<bean class="org.gridgain.grid.spi.loadbalancing.adaptive.GridAdaptiveLoadBalancingSpi">;
<property name="loadProbe">
<bean class="org.gridgain.grid.spi.loadbalancing.adaptive.GridAdaptiveJobCountLoadProbe">
<property name="useAverage" value="true"/>
</bean>
<property>
</bean>
</property>
Configuration
The following configuration parameters can be used to configure GridAdaptiveLoadBalancingSpi ![]()
| Setter Method | Description | Optional | Default |
|---|---|---|---|
| setLoadProbe(GridAdaptiveLoadProbe) |
This configuration parameter supplies a custom algorithm for probing a node's load. | Yes | Default value is GridAdaptiveCpuLoadProbe |
Examples
As any GridGain SPI, GridAdaptiveLoadBalancingSpi ![]()
GridAdaptiveLoadBalancingSpi spi = new GridAdaptiveLoadBalancingSpi(); // Configure probe to use latest job execution time vs. average. GridAdaptiveProcessingTimeLoadProbe probe = new GridAdaptiveProcessingTimeLoadProbe(false); spi.setLoadProbe(probe); 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.adaptive.GridAdaptiveLoadBalancingSpi"> <property name="loadProbe"> <bean class="org.gridgain.grid.spi.loadbalancing.adaptive.GridAdaptiveProcessingTimeLoadProbe"> <constructor-arg value="false"/> </bean> </property> </bean> </property> ... </bean>

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