Silk0vsky
Silk0vsky

Reputation: 1032

Akka dispatcher configuration for io-related actors

I'm configuring some general dispatcher for actors related to blocking io & trying to find the appropriate configuration.

The IO-related tasks are not CPU-consuming so I need such configuration that allow to utilize the max available threads before queuing the tasks.

Currently I'm thinking about.

io-dispatcher {
  type = Dispatcher
  executor = "thread-pool-executor"
  thread-pool-executor {
    keep-alive-time = 30s
    fixed-pool-size = off
    core-pool-size-min = 128
    core-pool-size-max = 128
    max-pool-size-min = 128
    max-pool-size-max = 128

    allow-core-timeout = on
  }

}

In such way I'm going to get a shrinking pool with up to 128 threads.

Is it correct way to achieve such purpose?

Upvotes: 0

Views: 238

Answers (1)

Pedro
Pedro

Reputation: 1072

It seems contradictory that you explicitly set fixed-pool-size = off but you then configure the thread pool exactly like a fixed size pool. The following configuration is in my opinion identical to yours:

io-dispatcher {
  type = Dispatcher
  executor = "thread-pool-executor"
  thread-pool-executor {
    keep-alive-time = 30s
    fixed-pool-size = 128
    allow-core-timeout = on
  }
}

Other than that, choosing your pool depends mostly on your needs and it may need some tuning. If you expect a high thread demand from your application most of the time, then you may be ok with your current configuration.

If the demand instead consists mostly of peaks, but is much lower most of the time, you would be better off lowering your core pool size. With your current configuration, even in periods when you only need a few threads (e.g. 10), your pool will have 128 threads. This is because every time a new task arrives to your pool, it will not reuse an existing thread if the pool size is less than 128, it will just create a new thread instead, trying to reach the core size. Again, in low demand periods, this may be a wasteful thread allocation. In such scenarios, set the core size to the average demand, and the max size to something more than the peak demand.

Explanation of the ThreadPoolExecutor is great in the javadoc: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ThreadPoolExecutor.html.

Upvotes: 2

Related Questions