Number of dispatcher threads, etc

Please clarify the following queries;

My laptop has 12 logical cores.

  1. I see around 8 default-dispatcher threads are created. Where is that number defined?

  2. I see either dispatchers of types default-dispatcher or internal-dispatcher are created in my setup. How is this decided?

  3. We could see the dispatcher threads in the Debug mode of any IDE. Is there any way to visualize the Akka actors?

  4. I have observed that the dispatcher threads die automatically when I leave the program running for some time. Please explain the reason for this. Does actor system auto-create and auto-delete the dispatchers?

  5. I see a number after default-dispatcher in the logs. What does this number indicate? Does it indicate the thread number being allocated by the dispatcher for an actor?
    Example: 2022-07-02 10:39:25.482 [EventProcessor-akka.actor.default-dispatcher-5] DEBUG

The default executor implementation for the default dispatcher is fork-join.

So the settings you are looking for are generally under akka.actor.default-dispatcher.fork-join-executor . And the number of threads for executor is going to be dynamically maintained by the fork join pool. (See the Javadoc for ForkJoinPool: The pool attempts to maintain enough active (or available) threads by dynamically adding, suspending, or resuming internal worker threads, even if some tasks are stalled waiting to join others.

What sometimes confuses people is that there are three fork-join parallelism settings in Akka: parallelism-min (default 8), parallelism-factor (default 1.0), and parallelism-max (default 64). The important thing to note is that these do not set a min/max on the thread pool. These three settings merely are used to calculate the single “parallelism” value passed into the ForkJoinPool when the ForkJoinPool is created. As we noted above in the ForkJoinPool, at runtime the thread pool will be adjusted dynamically to optimize throughput up to that parallelism maximum.

The parallelism-factor is multiplied by the number of cores that the JVM sees (subject to hyperthreading, containers, etc.). In your case, presumably 12 in your case. That value is then compared to the parallelism min and max to determine the actual parallelism passed in. i.e. no matter how small the environment you are in, it will always pass at least 8, and no matter how big the environment no more than 64.

So, presumably your maximum number of threads is 12. But the actual number of threads is dynamic. There’s nothing specifying 8 threads in your environment: that’s probably just an initial guess by the JVM. If you pushed the system hard you’d get all 12 spawned. And, as you’ve noticed, if the system is idle some of those 8 will be stopped.

And yes, in the standard Akka logs, the dispatcher thread number is included.

1 Like