简体   繁体   中英

Understanding dispatchers in akka

I read the documentation about dispatchers on the official site . but it's still not clear about what dispatcher is the beast. For example, it may be configured as follows:

my-thread-pool-dispatcher {
  # Dispatcher is the name of the event-based dispatcher
  type = Dispatcher
  # What kind of ExecutionService to use
  executor = "thread-pool-executor"
  # Configuration for the thread pool
  thread-pool-executor {
    # minimum number of threads to cap factor-based core number to
    core-pool-size-min = 2
    # No of core threads ... ceil(available processors * factor)
    core-pool-size-factor = 2.0
    # maximum number of threads to cap factor-based number to
    core-pool-size-max = 10
  }
  # Throughput defines the maximum number of messages to be
  # processed per actor before the thread jumps to the next actor.
  # Set to 1 for as fair as possible.
  throughput = 100
}

QUESTIONS:

  1. Does it mean that any configured dispatcher represented by the only one instance per actor system?

  2. Can one instance of a dispatcher manage more than one executors (thread pool, fork-join pool)?

  3. If there's only one instance of each configured dispatcher, how do different actors (perhaps on different nodes) interact with it?

Easiest is to think about a dispatcher as about a thread pool (which it really is) that is used to run your actors. Depending on the nature of your actors you can run them on fork-join thread pool (most common) or on CachedThreadPool (if you're dong IO) etc. I highly recommend this article that explains thread pools very nicely.

To answer the specific questions:

  1. Yes, you have one Dispatcher instance per configuration entry. You can have as many configurations as you want though (although it's likely not practical to have more than a few Dispatchers). Effectively config you described above creates you a named Dispatcher instance.
  2. Dispatcher is a sort of wrapper around Executor (as I understand it) to facilitate communication with actor API. So no, one dispatcher means one executor.
  3. There is a default system dispatcher that is used by actors when other dispatcher is not explicitly specified. Documentation you referred explains how to run actors on non-default dispatchers, either though API or through configuration. I don't quite understand "different nodes" part of the question. Dispatchers are concepts within JVM. When actors communicate across nodes dispatcher being used is not relevant. If that does not answer your question, please clarify.

You can create multiple Dispatchers of the same kind using the config above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM