diff --git a/akka-actor/src/main/scala/akka/actor/Scheduler.scala b/akka-actor/src/main/scala/akka/actor/Scheduler.scala index 202c580bf5..749b0559db 100644 --- a/akka-actor/src/main/scala/akka/actor/Scheduler.scala +++ b/akka-actor/src/main/scala/akka/actor/Scheduler.scala @@ -30,6 +30,11 @@ private final case class SchedulerException(msg: String) extends akka.AkkaExcept * 1) the system’s com.typesafe.config.Config (from system.settings.config) * 2) a akka.event.LoggingAdapter * 3) a java.util.concurrent.ThreadFactory + * + * Please note that this scheduler implementation is higly optimised for high-throughput + * and high-frequency events. It is not to be confused with long-term schedulers such as + * Quartz. The scheduler will throw an exception if attempts are made to schedule too far + * into the future (which by default is around 8 months (`Int.MaxValue` seconds). */ trait Scheduler { /** @@ -91,6 +96,9 @@ trait Scheduler { * If the `Runnable` throws an exception the repeated scheduling is aborted, * i.e. the function will not be invoked any more. * + * @throws IllegalArgumentException if the given delays exceed the maximum + * reach (calculated as: `delay / tickNanos > Int.MaxValue`). + * * Java API */ def schedule( @@ -102,6 +110,9 @@ trait Scheduler { * Schedules a message to be sent once with a delay, i.e. a time period that has * to pass before the message is sent. * + * @throws IllegalArgumentException if the given delays exceed the maximum + * reach (calculated as: `delay / tickNanos > Int.MaxValue`). + * * Java & Scala API */ final def scheduleOnce( @@ -118,6 +129,9 @@ trait Scheduler { * Schedules a function to be run once with a delay, i.e. a time period that has * to pass before the function is run. * + * @throws IllegalArgumentException if the given delays exceed the maximum + * reach (calculated as: `delay / tickNanos > Int.MaxValue`). + * * Scala API */ final def scheduleOnce(delay: FiniteDuration)(f: ⇒ Unit)( @@ -129,6 +143,9 @@ trait Scheduler { * Schedules a Runnable to be run once with a delay, i.e. a time period that * has to pass before the runnable is executed. * + * @throws IllegalArgumentException if the given delays exceed the maximum + * reach (calculated as: `delay / tickNanos > Int.MaxValue`). + * * Java & Scala API */ def scheduleOnce( diff --git a/akka-docs/rst/java/scheduler.rst b/akka-docs/rst/java/scheduler.rst index 12e31b0681..5e9c8cc9f3 100644 --- a/akka-docs/rst/java/scheduler.rst +++ b/akka-docs/rst/java/scheduler.rst @@ -1,9 +1,8 @@ .. _scheduler-java: -################## - Scheduler -################## +Scheduler +######### Sometimes the need for making things happen in the future arises, and where do you go look then? Look no further than ``ActorSystem``! There you find the @@ -15,6 +14,20 @@ You can schedule sending of messages to actors and execution of tasks (functions or Runnable). You will get a ``Cancellable`` back that you can call :meth:`cancel` on to cancel the execution of the scheduled operation. +The scheduler in Akka is designed for high-throughput of thousands up to millions +of triggers. The prime use-case being triggering Actor receive timeouts, Future timeouts, +circuit breakers and other time dependent events which happen all-the-time and in many +instances at the same time. The implementation is based on a Hashed Wheel Timer, which is +a known datastructure and algorithm for handling such use cases, refer to the `Hashed and Hierarchical Timing Wheels`_ +whitepaper by Varghese and Lauck if you'd like to understand its inner workings. + +The Akka scheduler is **not** designed for long-term scheduling (see `akka-quartz-scheduler`_ +instead for this use case) nor is it to be used for higly precise firing of the events. +The maximum amount of time into the future you can schedule an event to trigger is around 8 months, +which in practice is too much to be useful since this would assume the system never went down during that period. +If you need long-term scheduling we highly recommend looking into alternative schedulers, as this +is not the use-case the Akka scheduler is implemented for. + .. warning:: The default implementation of ``Scheduler`` used by Akka is based on job @@ -23,6 +36,9 @@ You can schedule sending of messages to actors and execution of tasks that is (over)due. The accuracy of the default Scheduler can be modified by the ``akka.scheduler.tick-duration`` configuration property. +.. _akka-quartz-scheduler: https://github.com/enragedginger/akka-quartz-scheduler +.. _Hashed and Hierarchical Timing Wheels: http://www.cs.columbia.edu/~nahum/w6998/papers/sosp87-timing-wheels.pdf + Some examples ------------- diff --git a/akka-docs/rst/scala/scheduler.rst b/akka-docs/rst/scala/scheduler.rst index 62667df27e..6f9c32e9dd 100644 --- a/akka-docs/rst/scala/scheduler.rst +++ b/akka-docs/rst/scala/scheduler.rst @@ -1,9 +1,8 @@ .. _scheduler-scala: -################### - Scheduler -################### +Scheduler +######### Sometimes the need for making things happen in the future arises, and where do you go look then? Look no further than ``ActorSystem``! There you find the @@ -15,6 +14,20 @@ You can schedule sending of messages to actors and execution of tasks (functions or Runnable). You will get a ``Cancellable`` back that you can call :meth:`cancel` on to cancel the execution of the scheduled operation. +The scheduler in Akka is designed for high-throughput of thousands up to millions +of triggers. The prime use-case being triggering Actor receive timeouts, Future timeouts, +circuit breakers and other time dependent events which happen all-the-time and in many +instances at the same time. The implementation is based on a Hashed Wheel Timer, which is +a known datastructure and algorithm for handling such use cases, refer to the `Hashed and Hierarchical Timing Wheels`_ +whitepaper by Varghese and Lauck if you'd like to understand its inner workings. + +The Akka scheduler is **not** designed for long-term scheduling (see `akka-quartz-scheduler`_ +instead for this use case) nor is it to be used for higly precise firing of the events. +The maximum amount of time into the future you can schedule an event to trigger is around 8 months, +which in practice is too much to be useful since this would assume the system never went down during that period. +If you need long-term scheduling we highly recommend looking into alternative schedulers, as this +is not the use-case the Akka scheduler is implemented for. + .. warning:: The default implementation of ``Scheduler`` used by Akka is based on job @@ -23,6 +36,9 @@ You can schedule sending of messages to actors and execution of tasks that is (over)due. The accuracy of the default Scheduler can be modified by the ``akka.scheduler.tick-duration`` configuration property. +.. _akka-quartz-scheduler: https://github.com/enragedginger/akka-quartz-scheduler +.. _Hashed and Hierarchical Timing Wheels: http://www.cs.columbia.edu/~nahum/w6998/papers/sosp87-timing-wheels.pdf + Some examples -------------