GridGain™ 2.1.0
Java API Specification

org.gridgain.grid.spi.loadbalancing.adaptive
Interface GridAdaptiveLoadProbe

All Known Implementing Classes:
GridAdaptiveBenchmarkLoadProbe, GridAdaptiveCpuLoadProbe, GridAdaptiveJobCountLoadProbe, GridAdaptiveProcessingTimeLoadProbe

public interface GridAdaptiveLoadProbe

Pluggable implementation of node load probing. Implementations of this can be configured to be used with GridAdaptiveLoadBalancingSpi by setting GridAdaptiveLoadBalancingSpi.setLoadProbe(GridAdaptiveLoadProbe) configuration parameter.

Note that if GridAdaptiveLoadProbe.getLoad(GridNode, int) returns a value of 0, then implementation will assume that load value is simply not available and will try to calculate an average of load values for other nodes. If such average cannot be obtained (all node load values are 0), then a value of 1 will be used.

By default, GridAdaptiveCpuLoadProbe probing implementation is used.

Example

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();
     }
 }
 
Below is an example of how a probe shown above would be configured with GridAdaptiveLoadBalancingSpi SPI:
 <property name="loadBalancingSpi">
     <bean class="org.gridgain.grid.spi.loadbalancing.adaptive.GridAdaptiveLoadBalancingSpi">
         <property name="loadProbe">
             <bean class="foo.bar.FooBarLoadProbe">
                 <constructor-arg value="true"/>
             </bean>
         </property>
     </bean>
 </property>
 




See Also:

  Documentation
  Email Support
  Online Forums
  Issue Tracking

Author:   2005-2008 Copyright © GridGain Systems. All Rights Reserved. ver. 2.1.0

 

Method Summary
 double getLoad(GridNode node, int jobsSentSinceLastUpdate)
          Calculates load value for a given node.
 

Method Detail

getLoad

double getLoad(GridNode node,
               int jobsSentSinceLastUpdate)
Calculates load value for a given node. Specific implementations would usually take into account some of the values provided by GridNode.getMetrics() method. For example, load can be calculated based on job execution time or number of active jobs, or CPU/Heap utilization.

Note that if GridAdaptiveLoadProbe.getLoad(GridNode, int) returns a value of 0, then implementation will assume that load value is simply not available and will try to calculate an average of load values for other nodes. If such average cannot be obtained (all node load values are 0), then a value of 1 will be used.

Parameters:
node - Grid node to calculate load for.
jobsSentSinceLastUpdate - Number of jobs sent to this node since last metrics update. This parameter may be useful when implementation takes into account the current job count on a node.
Returns:
Non-negative load value for the node (zero and above).

GridGain™ 2.1.0
Java API Specification

GridGain™ - Grid Computing Made Simple, ver. 2.1.0.19122008
2005-2008 Copyright © GridGain Systems. All Rights Reserved.