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

Creates a new DefaultResizer from the given configuration

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, scala.concurrent.duration.FiniteDuration stopDelay, 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()
          Fraction of routees to be removed when the resizer reaches the backoffThreshold.
 double backoffThreshold()
          Minimum fraction of busy routees before backing off.
 int capacity(scala.collection.IndexedSeq<ActorRef> 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.
 boolean isTimeForResize(long messageCounter)
          Is it time for resizing.
 int lowerBound()
          The fewest number of routees the router should ever have.
 int messagesPerResize()
          Number of messages between resize operation.
 int pressure(scala.collection.IndexedSeq<ActorRef> routees)
          Number of routees considered busy, or above 'pressure level'.
 int pressureThreshold()
          Threshold to evaluate if routee is considered to be busy (under pressure).
 int rampup(int pressure, int capacity)
          Computes a proposed positive (or zero) capacity delta using the configured rampupRate.
 double rampupRate()
          Percentage to increase capacity whenever all routees are busy.
 void resize(RouteeProvider routeeProvider)
          Decide if the capacity of the router need to be changed.
 scala.concurrent.duration.FiniteDuration stopDelay()
          When the resizer reduce the capacity the abandoned routee actors are stopped with PoisonPill after this delay.
 int upperBound()
          The most number of routees the router should ever have.
 
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,
                      scala.concurrent.duration.FiniteDuration stopDelay,
                      int messagesPerResize)

DefaultResizer

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

Method Detail

apply

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


lowerBound

public int lowerBound()
The fewest number of routees the router should ever have.


upperBound

public int upperBound()
The most number of routees the router should ever have. Must be greater than or equal to lowerBound.


pressureThreshold

public int pressureThreshold()
Threshold to evaluate if routee is considered to be busy (under pressure). Implementation depends on this value (default is 1).


rampupRate

public double rampupRate()
Percentage to increase capacity whenever all routees are busy. For example, 0.2 would increase 20% (rounded up), i.e. if current capacity is 6 it will request an increase of 2 more routees.


backoffThreshold

public double backoffThreshold()
Minimum fraction of busy routees before backing off. For example, if this is 0.3, then we'll remove some routees only when less than 30% of routees are busy, i.e. if current capacity is 10 and 3 are busy then the capacity is unchanged, but if 2 or less are busy the capacity is decreased.

Use 0.0 or negative to avoid removal of routees.


backoffRate

public double backoffRate()
Fraction of routees to be removed when the resizer reaches the backoffThreshold. For example, 0.1 would decrease 10% (rounded up), i.e. if current capacity is 9 it will request an decrease of 1 routee.


stopDelay

public scala.concurrent.duration.FiniteDuration stopDelay()
When the resizer reduce the capacity the abandoned routee actors are stopped with PoisonPill after this delay. The reason for the delay is to give concurrent messages a chance to be placed in mailbox before sending PoisonPill. Use 0 seconds to skip delay.


messagesPerResize

public int messagesPerResize()
Number of messages between resize operation. Use 1 to resize before each message.


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

resize

public void resize(RouteeProvider routeeProvider)
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. Create and register more routees with routeeProvider.registerRoutees(newRoutees) or remove routees with routeeProvider.unregisterRoutees(abandonedRoutees) and sending PoisonPill to them.

This method is invoked only in the context of the Router actor in order to safely create/stop children.

Specified by:
resize in interface Resizer

capacity

public int capacity(scala.collection.IndexedSeq<ActorRef> 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.IndexedSeq<ActorRef> 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)