Load Balancing

31.1. Overview

Load balancing is the process of distributing load among a set of processors in a smart way for exploiting the parallelism and minimize the response time. There are two main approaches to distributed load balancing: work sharing, in which processors try to equalize the load among them, and work stealing, in which idle processor request extra work.

The load balancing uses the migration to move objects from a node to an other : PAMobileAgent.migrateTo(object,node,false). (see Chapter 11, Mobile Agents And Migration for more details).

31.2. Metrics

The load balancing need metrics to evaluate each node and so to take a decision. You can define your own Metrics (CPU Load, number of active objects, communication between active objects ...).

31.2.1. MetricFactory and Metric classes

You must implement two classes : MetricFactory and Metric (package org.objectweb.proactive.loadbalancing.metrics).

31.2.1.1. MetricFactory

You have to implements the method public Metric getNewMetric( ) which returns a new Metric.

31.2.1.2. Metric

There are two concepts : the rank and the load. The rank is used to compare two nodes without considering the load (ex: CPU mHz). The load can evoluate in time

Three methods have to be implemented :

  • public void takeDecision(LoadBalancer lb) : this method has to call lb.startBalancing( ) (overload) or lb.stealWork( ) (underload)

  • public double getRanking() : this method returns the rank of the node.

  • public double getLoad() : this method returns the load of the node.

31.3. Using Load Balancing

There is two ways for using load balancing : manually in the application code or as a technical service.(see Chapter 23, Technical Service for more details).

31.3.1. In the application code

In order to ease the use of the load balancing, we provide static methods on the LoadBalancing class. First of all, you need to initialize the load balancing with the MetricFactory as described in the previous paragraph. You can specify a list of nodes at the initialization or later.

  Node[] nodes;
  Node node;
  //...  initialisation of nodes
  LoadBalancing.activateOn(nodes, new MyMetricFactory()); // or  LoadBalancing.activate(new
 MyMetricFactory()); 

  // to add a node
  LoadBalancing.addNode(node);

31.3.2. Technical Service

In your deployment descriptor, you have to define the load balancing technical service as following :

<technical-service id="LoadBalancingService" class=
"org.objectweb.proactive.loadbalancing.LoadBalancingTS">
  <arg name="MetricFactory" value="myPackage.myMetricFactory" />
</technical-service>

This service has to be applied on a Virtual Node :

<virtualNode name="Workers" property="multiple" technicalServiceId="LoadBalancingService"/>

31.4. Non Migratable Objects

Sometimes, active objects can't migrate : non-serializable attributes ...; in that case, you have to specify that these objects have to be ignored by the load balancing mechanism.

So, these objects have to implement the interface org.objectweb.proactive.loadbalancing.NotLoadBalanceableObject