akka.contrib.throttle

Throttler

object Throttler

Throttling

A throttler is an actor that is defined through a target actor and a rate (of type akka.contrib.throttle.Throttler.Rate). You set or change the target and rate at any time through the SetTarget(target) and SetRate(rate) messages, respectively. When you send the throttler any other message msg, it will put the message msg into an internal queue and eventually send all queued messages to the target, at a speed that respects the given rate. If no target is currently defined then the messages will be queued and will be delivered as soon as a target gets set.

A throttler understands actor messages of type akka.contrib.throttle.Throttler.SetTarget, akka.contrib.throttle.Throttler.SetRate, in addition to any other messages, which the throttler will consider as messages to be sent to the target.

Transparency

Notice that the throttler forwards messages, i.e., the target will see the original message sender (and not the throttler) as the sender of the message.

Persistence

Throttlers usually use an internal queue to keep the messages that need to be sent to the target. You therefore cannot rely on the throttler's inbox size in order to learn how much messages are outstanding.

It is left to the implementation whether the internal queue is persisted over application restarts or actor failure.

Processing messages

The target should process messages as fast as possible. If the target requires substantial time to process messages, it should distribute its work to other actors (using for example something like a BalancingDispatcher), otherwise the resulting system will always work below the threshold rate.

Example: Suppose the throttler has a rate of 3msg/s and the target requires 1s to process a message. This system will only process messages at a rate of 1msg/s: the target will receive messages at at most 3msg/s but as it handles them synchronously and each of them takes 1s, its inbox will grow and grow. In such a situation, the target should distribute its messages to a set of worker actors so that individual messages can be handled in parallel.

See also

akka.contrib.throttle.Throttler.Rate

akka.contrib.throttle.TimerBasedThrottler

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Throttler
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. case class Rate(numberOfCalls: Int, duration: FiniteDuration) extends Product with Serializable

    A rate used for throttling.

  2. implicit final class RateInt extends AnyVal

    Helper for some syntactic sugar.

  3. case class SetRate(rate: Rate) extends Product with Serializable

    Set the rate of a throttler.

  4. case class SetTarget(target: Option[ActorRef]) extends Product with Serializable

    Set the target of a throttler.

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  17. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  18. def toString(): String

    Definition Classes
    AnyRef → Any
  19. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped