Class DefaultOptimalSizeExploringResizer
- java.lang.Object
-
- akka.routing.DefaultOptimalSizeExploringResizer
-
- All Implemented Interfaces:
OptimalSizeExploringResizer,Resizer,java.io.Serializable,scala.Equals,scala.Product
public class DefaultOptimalSizeExploringResizer extends java.lang.Object implements OptimalSizeExploringResizer, scala.Product, java.io.Serializable
This resizer resizes the pool to an optimal size that provides the most message throughput.This resizer works best when you expect the pool size to performance function to be a convex function.
For example, when you have a CPU bound tasks, the optimal size is bound to the number of CPU cores. When your task is IO bound, the optimal size is bound to optimal number of concurrent connections to that IO service - e.g. a 4 node elastic search cluster may handle 4-8 concurrent requests at optimal speed.
It achieves this by keeping track of message throughput at each pool size and performing the following three resizing operations (one at a time) periodically:
* Downsize if it hasn't seen all routees ever fully utilized for a period of time. * Explore to a random nearby pool size to try and collect throughput metrics. * Optimize to a nearby pool size with a better (than any other nearby sizes) throughput metrics.
When the pool is fully-utilized (i.e. all routees are busy), it randomly choose between exploring and optimizing. When the pool has not been fully-utilized for a period of time, it will downsize the pool to the last seen max utilization multiplied by a configurable ratio.
By constantly exploring and optimizing, the resizer will eventually walk to the optimal size and remain nearby. When the optimal size changes it will start walking towards the new one.
It keeps a performance log so it's stateful as well as having a larger memory footprint than the default
Resizer. The memory usage is O(n) where n is the number of sizes you allow, i.e. upperBound - lowerBound.For documentation about the parameters, see the reference.conf - akka.actor.deployment.default.optimal-size-exploring-resizer
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface akka.routing.OptimalSizeExploringResizer
OptimalSizeExploringResizer.ResizeRecord, OptimalSizeExploringResizer.ResizeRecord$, OptimalSizeExploringResizer.UnderUtilizationStreak, OptimalSizeExploringResizer.UnderUtilizationStreak$
-
-
Constructor Summary
Constructors Constructor Description DefaultOptimalSizeExploringResizer(int lowerBound, int upperBound, double chanceOfScalingDownWhenFull, scala.concurrent.duration.Duration actionInterval, int numOfAdjacentSizesToConsiderDuringOptimization, double exploreStepSize, double downsizeRatio, scala.concurrent.duration.Duration downsizeAfterUnderutilizedFor, double explorationProbability, double weightOfLatestMetric)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static int$lessinit$greater$default$1()static double$lessinit$greater$default$10()static int$lessinit$greater$default$2()static double$lessinit$greater$default$3()static scala.concurrent.duration.Duration$lessinit$greater$default$4()static int$lessinit$greater$default$5()static double$lessinit$greater$default$6()static double$lessinit$greater$default$7()static scala.concurrent.duration.Duration$lessinit$greater$default$8()static double$lessinit$greater$default$9()scala.concurrent.duration.DurationactionInterval()static DefaultOptimalSizeExploringResizerapply(int lowerBound, int upperBound, double chanceOfScalingDownWhenFull, scala.concurrent.duration.Duration actionInterval, int numOfAdjacentSizesToConsiderDuringOptimization, double exploreStepSize, double downsizeRatio, scala.concurrent.duration.Duration downsizeAfterUnderutilizedFor, double explorationProbability, double weightOfLatestMetric)static intapply$default$1()static doubleapply$default$10()static intapply$default$2()static doubleapply$default$3()static scala.concurrent.duration.Durationapply$default$4()static intapply$default$5()static doubleapply$default$6()static doubleapply$default$7()static scala.concurrent.duration.Durationapply$default$8()static doubleapply$default$9()booleancanEqual(java.lang.Object x$1)doublechanceOfScalingDownWhenFull()DefaultOptimalSizeExploringResizercopy(int lowerBound, int upperBound, double chanceOfScalingDownWhenFull, scala.concurrent.duration.Duration actionInterval, int numOfAdjacentSizesToConsiderDuringOptimization, double exploreStepSize, double downsizeRatio, scala.concurrent.duration.Duration downsizeAfterUnderutilizedFor, double explorationProbability, double weightOfLatestMetric)intcopy$default$1()doublecopy$default$10()intcopy$default$2()doublecopy$default$3()scala.concurrent.duration.Durationcopy$default$4()intcopy$default$5()doublecopy$default$6()doublecopy$default$7()scala.concurrent.duration.Durationcopy$default$8()doublecopy$default$9()scala.concurrent.duration.DurationdownsizeAfterUnderutilizedFor()doubledownsizeRatio()booleanequals(java.lang.Object x$1)doubleexplorationProbability()doubleexploreStepSize()inthashCode()booleanisTimeForResize(long messageCounter)Is it time for resizing.intlowerBound()intnumOfAdjacentSizesToConsiderDuringOptimization()intproductArity()java.lang.ObjectproductElement(int x$1)java.lang.StringproductElementName(int x$1)scala.collection.Iterator<java.lang.Object>productIterator()java.lang.StringproductPrefix()voidreportMessageCount(scala.collection.immutable.IndexedSeq<Routee> currentRoutees, long messageCounter)Report the messageCount as well as current routees so that the it can collect metrics.intresize(scala.collection.immutable.IndexedSeq<Routee> currentRoutees)Decide if the capacity of the router need to be changed.java.lang.StringtoString()static scala.Option<scala.Tuple10<java.lang.Object,java.lang.Object,java.lang.Object,scala.concurrent.duration.Duration,java.lang.Object,java.lang.Object,java.lang.Object,scala.concurrent.duration.Duration,java.lang.Object,java.lang.Object>>unapply(DefaultOptimalSizeExploringResizer x$0)intupperBound()doubleweightOfLatestMetric()
-
-
-
Constructor Detail
-
DefaultOptimalSizeExploringResizer
public DefaultOptimalSizeExploringResizer(int lowerBound, int upperBound, double chanceOfScalingDownWhenFull, scala.concurrent.duration.Duration actionInterval, int numOfAdjacentSizesToConsiderDuringOptimization, double exploreStepSize, double downsizeRatio, scala.concurrent.duration.Duration downsizeAfterUnderutilizedFor, double explorationProbability, double weightOfLatestMetric)
-
-
Method Detail
-
$lessinit$greater$default$1
public static int $lessinit$greater$default$1()
-
$lessinit$greater$default$2
public static int $lessinit$greater$default$2()
-
$lessinit$greater$default$3
public static double $lessinit$greater$default$3()
-
$lessinit$greater$default$4
public static scala.concurrent.duration.Duration $lessinit$greater$default$4()
-
$lessinit$greater$default$5
public static int $lessinit$greater$default$5()
-
$lessinit$greater$default$6
public static double $lessinit$greater$default$6()
-
$lessinit$greater$default$7
public static double $lessinit$greater$default$7()
-
$lessinit$greater$default$8
public static scala.concurrent.duration.Duration $lessinit$greater$default$8()
-
$lessinit$greater$default$9
public static double $lessinit$greater$default$9()
-
$lessinit$greater$default$10
public static double $lessinit$greater$default$10()
-
apply
public static DefaultOptimalSizeExploringResizer apply(int lowerBound, int upperBound, double chanceOfScalingDownWhenFull, scala.concurrent.duration.Duration actionInterval, int numOfAdjacentSizesToConsiderDuringOptimization, double exploreStepSize, double downsizeRatio, scala.concurrent.duration.Duration downsizeAfterUnderutilizedFor, double explorationProbability, double weightOfLatestMetric)
-
apply$default$1
public static int apply$default$1()
-
apply$default$10
public static double apply$default$10()
-
apply$default$2
public static int apply$default$2()
-
apply$default$3
public static double apply$default$3()
-
apply$default$4
public static scala.concurrent.duration.Duration apply$default$4()
-
apply$default$5
public static int apply$default$5()
-
apply$default$6
public static double apply$default$6()
-
apply$default$7
public static double apply$default$7()
-
apply$default$8
public static scala.concurrent.duration.Duration apply$default$8()
-
apply$default$9
public static double apply$default$9()
-
unapply
public static scala.Option<scala.Tuple10<java.lang.Object,java.lang.Object,java.lang.Object,scala.concurrent.duration.Duration,java.lang.Object,java.lang.Object,java.lang.Object,scala.concurrent.duration.Duration,java.lang.Object,java.lang.Object>> unapply(DefaultOptimalSizeExploringResizer x$0)
-
lowerBound
public int lowerBound()
-
upperBound
public int upperBound()
-
chanceOfScalingDownWhenFull
public double chanceOfScalingDownWhenFull()
-
actionInterval
public scala.concurrent.duration.Duration actionInterval()
-
numOfAdjacentSizesToConsiderDuringOptimization
public int numOfAdjacentSizesToConsiderDuringOptimization()
-
exploreStepSize
public double exploreStepSize()
-
downsizeRatio
public double downsizeRatio()
-
downsizeAfterUnderutilizedFor
public scala.concurrent.duration.Duration downsizeAfterUnderutilizedFor()
-
explorationProbability
public double explorationProbability()
-
weightOfLatestMetric
public double weightOfLatestMetric()
-
isTimeForResize
public boolean isTimeForResize(long messageCounter)
Description copied from interface:ResizerIs 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:
isTimeForResizein interfaceResizer
-
reportMessageCount
public void reportMessageCount(scala.collection.immutable.IndexedSeq<Routee> currentRoutees, long messageCounter)
Description copied from interface:OptimalSizeExploringResizerReport the messageCount as well as current routees so that the it can collect metrics. Caution: this method is not thread safe.- Specified by:
reportMessageCountin interfaceOptimalSizeExploringResizer
-
resize
public int resize(scala.collection.immutable.IndexedSeq<Routee> currentRoutees)
Description copied from interface:ResizerDecide if the capacity of the router need to be changed. Will be invoked whenisTimeForResizereturns 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 routees. 0 will not change the routees.
This method is invoked only in the context of the Router actor.
-
copy
public DefaultOptimalSizeExploringResizer copy(int lowerBound, int upperBound, double chanceOfScalingDownWhenFull, scala.concurrent.duration.Duration actionInterval, int numOfAdjacentSizesToConsiderDuringOptimization, double exploreStepSize, double downsizeRatio, scala.concurrent.duration.Duration downsizeAfterUnderutilizedFor, double explorationProbability, double weightOfLatestMetric)
-
copy$default$1
public int copy$default$1()
-
copy$default$10
public double copy$default$10()
-
copy$default$2
public int copy$default$2()
-
copy$default$3
public double copy$default$3()
-
copy$default$4
public scala.concurrent.duration.Duration copy$default$4()
-
copy$default$5
public int copy$default$5()
-
copy$default$6
public double copy$default$6()
-
copy$default$7
public double copy$default$7()
-
copy$default$8
public scala.concurrent.duration.Duration copy$default$8()
-
copy$default$9
public double copy$default$9()
-
productPrefix
public java.lang.String productPrefix()
- Specified by:
productPrefixin interfacescala.Product
-
productArity
public int productArity()
- Specified by:
productArityin interfacescala.Product
-
productElement
public java.lang.Object productElement(int x$1)
- Specified by:
productElementin interfacescala.Product
-
productIterator
public scala.collection.Iterator<java.lang.Object> productIterator()
- Specified by:
productIteratorin interfacescala.Product
-
canEqual
public boolean canEqual(java.lang.Object x$1)
- Specified by:
canEqualin interfacescala.Equals
-
productElementName
public java.lang.String productElementName(int x$1)
- Specified by:
productElementNamein interfacescala.Product
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object x$1)
- Specified by:
equalsin interfacescala.Equals- Overrides:
equalsin classjava.lang.Object
-
-