Hello,
Thank you for your help. After reading your comment ("the router, not for
it's routees") I remembered about actor groups (as opposed to pools).
I defined a common pinned dispatcher (in application.conf, directly under
"akka" element):
pinnedDispatcher {
type = "PinnedDispatcher"
executor = "thread-pool-executor"
thread-pool-executor.allow-core-timeout = off
}
Then created worker actors first:
private lazy val workers = for (i <- 0 until MyWorkerCount) yield {
context.actorOf(Props[MyWorker].withDispatcher("pinnedDispatcher"),
"myWorker" + i) //actor names need to be unique
}
And then created round robin actor group:
private lazy val workerGroup =
context.actorOf(RoundRobinGroup(workers.map(_.path.toString)).props(),
"workerGroup")
Now each worker actor in the group is running on a separate thread, and
always on the same one.
Thanks,
M
On Tuesday, August 1, 2017 at 12:49:00 PM UTC-7, Rafał Sumisławski wrote:
>
> I'm not experienced with configuring routers from config, since I prefer
> using code, but as far as I understand you did set a dispatcher for the
> /master/worker - the router, not for it's routees - the actual worker
> actors. If you print the thread name in constructor an in receive of
> workers you should see that your using default-dispatcher.
>
> Something like this may be closer to what you're trying to achieve:
> akka.actor.deployment {
> /master/worker {
> pool-dispatcher = {
> type = "PinnedDispatcher"
> executor = "thread-pool-executor"
> thread-pool-executor.allow-core-timeout = off
> throughput = 1
> }
> router = round-robin-pool
> }
> }
>
> BTW AFAIK you shouldn't/don't have to configure thread pool size for a
> pinned dispatcher. It's creating a separate single-thread pool for each
> actor.
>
> W dniu wtorek, 1 sierpnia 2017 00:26:34 UTC+2 użytkownik mc napisał:
>>
>> Hello,
>>
>> I tried to use PinnedDispatcher using the following configuration (in
>> application.conf):
>>
>> app {
>> pinnedDispatcher {
>> type = "PinnedDispatcher"
>> executor = "thread-pool-executor"
>> thread-pool-executor.allow-core-timeout = off
>> thread-pool-executor {
>> core-pool-size-min = 2
>> core-pool-size-factor = 2.0
>> core-pool-size-max = 4
>> }
>> throughput = 1
>> }
>> }
>>
>> akka.actor.deployment {
>> /master/worker {
>> dispatcher = app.pinnedDispatcher
>> router = round-robin-pool
>> }
>> }
>>
>> This is my code for creating worker pool (inside MyMaster actor called
>> "master"):
>> private lazy val worker =
>> context.actorOf(FromConfig.props(Props[MyWorker]), "worker")
>>
>> Worker actors are receiving messages but it looks like actors created on
>> one thread are later executed on another thread.
>> Is my configuration incorrect? I thought that using pinned dispatcher
>> would guarantee that an actor created on a thread would later be always
>> called from that same thread.
>> I'd appreciate any help with this problem.
>> Thanks,
>>
>> M
>>
>>
>>
>> On Thursday, July 27, 2017 at 11:17:12 AM UTC-7, Rafał Sumisławski wrote:
>>>
>>> Hi
>>> A PinnedDispatcher may be what your looking for. It creates a dedicated
>>> thread for each actor.
>>>
>>> It's documented (with an example) here:
>>> http://doc.akka.io/docs/akka/current/scala/dispatchers.html#types-of-dispatchers
>>>
>>> Best Regards,
>>> Rafał
>>>
>>
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.