akka.routing
Class DefaultResizer

java.lang.Object
  extended by akka.routing.DefaultResizer
All Implemented Interfaces:
Resizer, java.io.Serializable, scala.Equals, scala.Product

public class DefaultResizer
extends java.lang.Object
implements Resizer, scala.Product, scala.Serializable

See Also:
Serialized Form

Constructor Summary
DefaultResizer(int lower, int upper)
          Java API constructor for default values except bounds.
DefaultResizer(int lowerBound, int upperBound, int pressureThreshold, double rampupRate, double backoffThreshold, double backoffRate, int messagesPerResize)
           
 
Method Summary
static DefaultResizer apply(com.typesafe.config.Config resizerConfig)
          Creates a new DefaultResizer from the given configuration
 int backoff(int pressure, int capacity)
          Computes a proposed negative (or zero) capacity delta using the configured backoffThreshold and backoffRate
 double backoffRate()
           
 double backoffThreshold()
           
 int capacity(scala.collection.immutable.IndexedSeq<Routee> routees)
          Returns the overall desired change in resizer capacity.
 int filter(int pressure, int capacity)
          This method can be used to smooth the capacity delta by considering the current pressure and current capacity.
static scala.Option<DefaultResizer> fromConfig(com.typesafe.config.Config resizerConfig)
           
 boolean isTimeForResize(long messageCounter)
          Is it time for resizing.
 int lowerBound()
           
 int messagesPerResize()
           
 int pressure(scala.collection.immutable.IndexedSeq<Routee> routees)
          Number of routees considered busy, or above 'pressure level'.
 int pressureThreshold()
           
 int rampup(int pressure, int capacity)
          Computes a proposed positive (or zero) capacity delta using the configured rampupRate.
 double rampupRate()
           
 int resize(scala.collection.immutable.IndexedSeq<Routee> currentRoutees)
          Decide if the capacity of the router need to be changed.
 int upperBound()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface scala.Product
productArity, productElement, productIterator, productPrefix
 
Methods inherited from interface scala.Equals
canEqual, equals
 

Constructor Detail

DefaultResizer

public DefaultResizer(int lowerBound,
                      int upperBound,
                      int pressureThreshold,
                      double rampupRate,
                      double backoffThreshold,
                      double backoffRate,
                      int messagesPerResize)

DefaultResizer

public DefaultResizer(int lower,
                      int upper)
Java API constructor for default values except bounds.

Parameters:
lower - (undocumented)
upper - (undocumented)
Method Detail

apply

public static DefaultResizer apply(com.typesafe.config.Config resizerConfig)
Creates a new DefaultResizer from the given configuration

Parameters:
resizerConfig - (undocumented)
Returns:
(undocumented)

fromConfig

public static scala.Option<DefaultResizer> fromConfig(com.typesafe.config.Config resizerConfig)

lowerBound

public int lowerBound()

upperBound

public int upperBound()

pressureThreshold

public int pressureThreshold()

rampupRate

public double rampupRate()

backoffThreshold

public double backoffThreshold()

backoffRate

public double backoffRate()

messagesPerResize

public int messagesPerResize()

isTimeForResize

public boolean isTimeForResize(long messageCounter)
Description copied from interface: Resizer
Is it time for resizing. Typically implemented with modulo of nth message, but could be based on elapsed time or something else. The messageCounter starts with 0 for the initial resize and continues with 1 for the first message. Make sure to perform initial resize before first message (messageCounter == 0), because there is no guarantee that resize will be done when concurrent messages are in play.

CAUTION: this method is invoked from the thread which tries to send a message to the pool, i.e. the ActorRef.!() method, hence it may be called concurrently.

Specified by:
isTimeForResize in interface Resizer
Parameters:
messageCounter - (undocumented)
Returns:
(undocumented)

resize

public int resize(scala.collection.immutable.IndexedSeq<Routee> currentRoutees)
Description copied from interface: Resizer
Decide if the capacity of the router need to be changed. Will be invoked when isTimeForResize returns true and no other resize is in progress.

Return the number of routees to add or remove. Negative value will remove that number of routees. Positive value will add that number of routess. 0 will not change the routees.

This method is invoked only in the context of the Router actor.

Specified by:
resize in interface Resizer
Parameters:
currentRoutees - (undocumented)
Returns:
(undocumented)

capacity

public int capacity(scala.collection.immutable.IndexedSeq<Routee> routees)
Returns the overall desired change in resizer capacity. Positive value will add routees to the resizer. Negative value will remove routees from the resizer.

Parameters:
routees - The current actor in the resizer
Returns:
the number of routees by which the resizer should be adjusted (positive, negative or zero)

pressure

public int pressure(scala.collection.immutable.IndexedSeq<Routee> routees)
Number of routees considered busy, or above 'pressure level'.

Implementation depends on the value of pressureThreshold (default is 1).

Parameters:
routees - the current resizer of routees
Returns:
number of busy routees, between 0 and routees.size

filter

public int filter(int pressure,
                  int capacity)
This method can be used to smooth the capacity delta by considering the current pressure and current capacity.

Parameters:
pressure - current number of busy routees
capacity - current number of routees
Returns:
proposed change in the capacity

rampup

public int rampup(int pressure,
                  int capacity)
Computes a proposed positive (or zero) capacity delta using the configured rampupRate.

Parameters:
pressure - the current number of busy routees
capacity - the current number of total routees
Returns:
proposed increase in capacity

backoff

public int backoff(int pressure,
                   int capacity)
Computes a proposed negative (or zero) capacity delta using the configured backoffThreshold and backoffRate

Parameters:
pressure - the current number of busy routees
capacity - the current number of total routees
Returns:
proposed decrease in capacity (as a negative number)