Package akka.routing

Class 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
    • 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: 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
      • reportMessageCount

        public void reportMessageCount​(scala.collection.immutable.IndexedSeq<Routee> currentRoutees,
                                       long messageCounter)
        Description copied from interface: OptimalSizeExploringResizer
        Report the messageCount as well as current routees so that the it can collect metrics. Caution: this method is not thread safe.

        Specified by:
        reportMessageCount in interface OptimalSizeExploringResizer
      • 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 routees. 0 will not change the routees.

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

        Specified by:
        resize in interface Resizer
      • 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:
        productPrefix in interface scala.Product
      • productArity

        public int productArity()
        Specified by:
        productArity in interface scala.Product
      • productElement

        public java.lang.Object productElement​(int x$1)
        Specified by:
        productElement in interface scala.Product
      • productIterator

        public scala.collection.Iterator<java.lang.Object> productIterator()
        Specified by:
        productIterator in interface scala.Product
      • canEqual

        public boolean canEqual​(java.lang.Object x$1)
        Specified by:
        canEqual in interface scala.Equals
      • productElementName

        public java.lang.String productElementName​(int x$1)
        Specified by:
        productElementName in interface scala.Product
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object x$1)
        Specified by:
        equals in interface scala.Equals
        Overrides:
        equals in class java.lang.Object