example.loadbalance
Class AvgBalance

java.lang.Object
  extended by peersim.vector.SingleValueHolder
      extended by example.loadbalance.BasicBalance
          extended by example.loadbalance.AvgBalance
All Implemented Interfaces:
java.lang.Cloneable, CDProtocol, Protocol, SingleValue

public class AvgBalance
extends BasicBalance

This class implements the advanced load balancing scheme: each node is aware of the average load of the system. If its load value is lower that the average, then it pull some load with its most loaded neighbor. Otherwise, if its load is higher than the average, it pushes some load to its least loaded neighbor.

The load exchanged is limited by the BasicBalance.PAR_QUOTA parameter. The class subclasses SingleValueHolder in order to be type compatible with its observers and initializers object companions.

As soon as a node is "balanced" (i.e., has the same load as the average value), it exits from the overlay shrinking the topology.


Parameter Summary
 
Parameters inherited from class example.loadbalance.BasicBalance
quota
 
Field Summary
protected static double average
          The overall system average load.
protected static boolean avg_done
          This flag indicates if the average value computation has been performed or not.
 
Fields inherited from class example.loadbalance.BasicBalance
quota
 
Fields inherited from class peersim.vector.SingleValueHolder
value
 
Constructor Summary
AvgBalance(java.lang.String prefix)
          Creates a new AvgBalance protocol instance.
 
Method Summary
 void nextCycle(Node node, int protocolID)
          Using an underlying Linkable protocol choses a neighbor and performs a variance reduction step.
protected static void suspend(Node node)
          Let a node exit from the network as soon as it has the required load (equal to the average).
 
Methods inherited from class example.loadbalance.BasicBalance
doTransfer, resetQuota
 
Methods inherited from class peersim.vector.SingleValueHolder
clone, getValue, setValue, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface peersim.core.Protocol
clone
 

Field Detail

average

protected static double average
The overall system average load. It is computed once by calculateAVG(int) method.


avg_done

protected static boolean avg_done
This flag indicates if the average value computation has been performed or not. Default is NO.

Constructor Detail

AvgBalance

public AvgBalance(java.lang.String prefix)
Creates a new AvgBalance protocol instance. Reads the configuration parameters invoking the subclass constructor.

Parameters:
prefix - The component prefix declared in the configuration file.
Method Detail

suspend

protected static void suspend(Node node)
Let a node exit from the network as soon as it has the required load (equal to the average).

Parameters:
node - the node to switch off.

nextCycle

public void nextCycle(Node node,
                      int protocolID)
Description copied from class: BasicBalance
Using an underlying Linkable protocol choses a neighbor and performs a variance reduction step.

Specified by:
nextCycle in interface CDProtocol
Overrides:
nextCycle in class BasicBalance
Parameters:
node - the node on which this component is run.
protocolID - the id of this protocol in the protocol array.