Akka.io: Thread per Actor

2019-06-11 16:48发布

问题:

There is a requirement to run 1 thousand operations asynchoniosly, I've chosen to use Akka. Warpping in Actor Ref executor and sending 1 thousand messages to ref.

How can I be sure that:

  • all 1 thousand messages will be dispatched in asnc way
  • each will hold the separate, in-depended thread (that is requirement because of io usage).

回答1:

You can use the PinnedDispatcher to guarantee one thread per actor, and everything in Akka is async, so you can be guaranteed the messages are async. If you send your messages using the ! operator, the message is sent in a fire-and-forget manner.

See this for more details.



回答2:

Try to use PinnedDispatcher

Configuration example & code is here

No blocking until bounded mailbox will be used



回答3:

Thanks all for the responses, actually for my case combination of RoundRobinRouter (where number of routes is equal to number of expected threads) and PinnedDispatcher with flag thread-pool-executor.allow-core-timeout=off is working fine.



标签: scala akka