Class DefaultOptimalSizeExploringResizer
- All Implemented Interfaces:
Serializable,OptimalSizeExploringResizer,Resizer,scala.Equals,scala.Product
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 - pekko.actor.deployment.default.optimal-size-exploring-resizer
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.pekko.routing.OptimalSizeExploringResizer
OptimalSizeExploringResizer.ResizeRecord, OptimalSizeExploringResizer.ResizeRecord$, OptimalSizeExploringResizer.UnderUtilizationStreak, OptimalSizeExploringResizer.UnderUtilizationStreak$ -
Constructor Summary
ConstructorsConstructorDescriptionDefaultOptimalSizeExploringResizer(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
Modifier and TypeMethodDescriptionstatic intstatic doublestatic intstatic doublestatic scala.concurrent.duration.Durationstatic intstatic doublestatic doublestatic scala.concurrent.duration.Durationstatic doublescala.concurrent.duration.Durationapply(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 intstatic doublestatic intstatic doublestatic scala.concurrent.duration.Durationstatic intstatic doublestatic doublestatic scala.concurrent.duration.Durationstatic doublebooleandoublecopy(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) intdoubleintdoublescala.concurrent.duration.Durationintdoubledoublescala.concurrent.duration.Durationdoublescala.concurrent.duration.DurationdoublebooleandoubledoubleinthashCode()booleanisTimeForResize(long messageCounter) Is it time for resizing.intintintproductElement(int x$1) productElementName(int x$1) scala.collection.Iterator<Object>voidreportMessageCount(scala.collection.immutable.IndexedSeq<Routee> currentRoutees, long messageCounter) Report the messageCount as well as current routees so that the it can collect metrics.intDecide if the capacity of the router need to be changed.toString()static scala.Option<scala.Tuple10<Object,Object, Object, scala.concurrent.duration.Duration, Object, Object, Object, scala.concurrent.duration.Duration, Object, Object>> intdoubleMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface scala.Product
productElementNames
-
Constructor Details
-
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 Details
-
$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
-
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
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
- Specified by:
productPrefixin interfacescala.Product
-
productArity
public int productArity()- Specified by:
productArityin interfacescala.Product
-
productElement
- Specified by:
productElementin interfacescala.Product
-
productIterator
- Specified by:
productIteratorin interfacescala.Product
-
canEqual
- Specified by:
canEqualin interfacescala.Equals
-
productElementName
- Specified by:
productElementNamein interfacescala.Product
-
hashCode
public int hashCode() -
toString
-
equals
-