0
votes

I have a play application built on java using Akka actor. Recently I came across performance issues with related to parallelism. I have gone through Google and found that we can assign custom/pinned dispatchers/executors to actors. At the time of actor creation, I have named the actor with actor name appended with unique ID.

Is there a way to specify my actors to use pinned dispatcher when the actor names are appended with unique ID.

I am trying to update the application.conf as below and not getting the result as expected. It is still using default dispatcher.

My actors are at akka://application/user/actor

akka.actor.deployment {
  "/actorName*" {
       dispatcher =  mycustom-dispatcher
  }
}

References I used: http://doc.akka.io/docs/akka/2.1.4/java/dispatchers.html#Setting_the_dispatcher_for_an_Actor

3
The latest config reference ( doc.akka.io/docs/akka/2.4.17/java/dispatchers.html ) doesn't have a wildcard * in its example. have you tried without it? Are you sure there are no typos anywhere? How are you confirming it's still using the default one?Diego Martinoia
@Diego, the logs confirming that the actor using the default dispatcher.Dhana

3 Answers

1
votes

Yes, you can explicitly assign a dispatcher to your actor[s].

import akka.actor.Props
val myActor =
  context.actorOf(Props[MyActor].withDispatcher("my-dispatcher"), "myactor1")

or java variant:

ActorRef myActor =
  system.actorOf(Props.create(MyUntypedActor.class).withDispatcher("my-dispatcher"),
    "myactor3");

with configuration

my-dispatcher {
  executor = "thread-pool-executor"
  type = PinnedDispatcher
}

Check for more the akka-docs

0
votes

You have to specify which dispatcher to use with your actors, usually you pass an execution context where you can specify which dispatcher to use:

implicit val executionContext = system.dispatchers.lookup("my-dispatcher")

You can also change the default dispatcher like specified here: https://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html#default-dispatcher

0
votes
akka.actor.deployment {
  "/actorName*" {
    dispatcher =  mycustom-dispatcher
  }
}

The above doesn't work, because (from the documentation):

  • wildcards cannot be used to partially match section, like this: /foo*/bar, /f*o/bar etc.

You can, however, use a wildcard to match all actors at a certain level in the actor hierarchy. For example, let's say that all of the actors for which you want to use the custom dispatcher live under akka://application/user/someParent/. You could then configure all of someParent's direct children in the following way:

akka.actor.deployment {
  "/someParent/*" {
    dispatcher =  mycustom-dispatcher
  }
}

Read the linked documentation for more options.