Can I schedule the task to run in less than 10ms

I noticed that scheduler.schedule in Akka doesn't work for schedules less than 10ms. For example, I tried below and I only get a message every 10ms. Is it possible to reduce this, i.e. Increase the frequency?

Thanks Des

akka.actor.ActorSystem("Test").actorOf(Props(new akka.actor.Actor {

    val system = context.system
    import system.dispatcher

    system.scheduler.schedule(0 milliseconds, 2 milliseconds, self, "Test")

    def receive = {

        case msg => 
            println("Received[" + System.currentTimeMillis + "]: " + msg)
    }
}), "Test")

      

+3


source to share


2 answers


The scheduler is not optimized for very precise scheduling, instead it is optimized for a little overhead scheduling a large number of timers (for example, "every Actor in your system wants to have an event scheduled"). When you schedule something, it gets into the "bucket" along with other tasks for that time interval and will not execute until the specified timeout.

The default for the bucket is 10ms as you noticed. You can tweak this setting with akka.scheduler.tick-duration

, but keep in mind that relying on it to be precise may not be the best idea (system wait, garbage collection, etc.).



You can read more details on this in this akka-user thread: Using the scheduler and deadline to simulate some backends

+6


source


You can use https://github.com/typesafehub/akka-quartz-scheduler/ to go up to 1 millisecond.



The project was updated with Akka 2.4.x.

0


source







All Articles