Custom dispatcher seems to be available but not being used for actor

293 views
Skip to first unread message

lakshmi

unread,
Oct 16, 2014, 1:46:37 AM10/16/14
to akka...@googlegroups.com
Hi,

I'm using Akka 2.3.5 with Java 8. I would like to use a custom dispatcher for some db-related actors, and use the default otherwise. Even though my actor seems to be created with the correct dispatcher (which it tells me so in the logs below), the actual dispatcher it is using is the default dispatcher. I'm not sure what is missing in this setup. 

Please help!

Below, I am associating the RedisStatusSyncActor with the db-dispatcher via code (configuration is not working for this either). As you can see in the highlighted log below, the dispatcher it reports having is db-dispatcher, but the thread that is logging that line in the actor is the default dispatcher - Abc-akka.actor.default-dispatcher-3

In application.conf:

    akka {
      actor {

        db-dispatcher {
          type = Dispatcher
          executor = "thread-pool-executor"

          thread-pool-executor {
            core-pool-size-min = 2
            core-pool-size-factor = 2.0
            core-pool-size-max = 4
          }

          throughput = 5
        }

     deployment {
      StatusSyncActor {
        sync-interval-millis = 120000
      }
     }

  }
}


Created RedisStatusSyncActor In ParentActor.java:

        public static final String DB_THREAD_POOL_DISPATCHER = "akka.actor.db-dispatcher";
....
        context().actorOf(RedisStatusSyncActor.props(configuration, statusRedisConfiguration, eventBus).withDispatcher(DB_THREAD_POOL_DISPATCHER));



log:

2014-10-15 22:20:39,328 [main] INFO  com.abc.system - Starting system.
2014-10-15 22:20:39,402 [Abc-akka.actor.default-dispatcher-3] INFO  c.a.s.actor.AbcActor - Starting db actor
2014-10-15 22:20:39,412 [Abc-akka.actor.default-dispatcher-3] INFO  c.a.s.r.actor.RedisStatusSyncActor - getContext().props().dispatcher() is akka.actor.db-dispatcher, context.dispatcher is Dispatcher[akka.actor.db-dispatcher]
2014-10-15 22:20:39,413 [Abc-akka.actor.default-dispatcher-3] INFO  c.a.s.r.actor.RedisStatusSyncActor - Started RedisStatusSyncActor


----------------------------------------------

The other weird thing I noticed is that if I cut short the application.conf without the "deployment" section, then it does actually use the db-dispatcher. Wonder why?

Thanks in advance for any insight you guys can provide!

L

Konrad Malawski

unread,
Oct 20, 2014, 3:14:58 AM10/20/14
to Akka User List
Hi lakshmi!
You have properly found the reason why this is so:
> The other weird thing I noticed is that if I cut short the application.conf without the "deployment" section, then it does actually use the db-dispatcher. Wonder why?

Configuration for dispatchers (in general the entire "Deploy" section) in the config object takes precedence over hardcoded things in the code.
The reasoning is that you code in one thing, but then based on environment want to reconfigure things in your app (on this server I give file A, so it's using A settings, on another one I give file B, so it's using B settings 

It's mentioned in the docs for dispatchers:
    If you define the dispatcherin the deployment configuration then this value will be used instead of programmatically provided parameter.
as well as routing docs (because that's where you'll very often use the deploy section).


Hope this helps!

-- Konrad


--
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Cheers,
Konrad 'ktoso' Malawski
hAkker @ Typesafe


lakshmi

unread,
Oct 21, 2014, 1:26:33 AM10/21/14
to akka...@googlegroups.com
Hi Konrad,

Thanks so much for your reply! I might need to clarify a little more here. 

The time when I said I removed the "akka.actor.deployment" section out of  the "akka.actor" path, everything else stopped working, because my router actors were configured in that section. Also it was not clear in my example earlier, but "StatusSyncActor" is actually a child of AbcActor. I had never defined the full path in akka.actor.deployment "AbcActor/StatusSyncActor", so I don't think the dispatcher was ever used from the configuration. It was only using it from the code. If I removed it from the code, it ended up using the default dispatcher.

Here are my various attempts, out of which case 1 seems to be the only time the dispatcher is even used according to the logs (please see highlighted log line). But it is throwing config errors for every other actor that was part of akka.actor.deployment, so it is not useful. 

Are you able to see any obvious mistake that causes the dispatcher to not be picked up in cases 2 and 3 where the deployment section is present? Is there a problem with my actor path (StatusSyncActor is not a router actor), that as a child actor, it is not getting configured correctly?

Thanks Konrad, I really appreciate your help with this!


case 1:

application.conf:

akka {
  actor {

    db-dispatcher {
      type = Dispatcher
      .....
    }
  }

  deployment {
    .. 
   // other actors and router actors here
  }

AbcActor.java:

        ActorRef statusRedisSyncActor = context().actorOf(StatusSyncActor.props(configuration, statusRedisConfiguration, eventBus).withDispatcher(DB_THREAD_POOL_DISPATCHER), STATUS_SYNC_ACTOR);


Log:

Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.actor.deployment.SearchHandlerActor'
at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:124)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:147)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:151)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:151)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:151)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:159)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:164)
at com.typesafe.config.impl.SimpleConfig.getConfigNumber(SimpleConfig.java:179)
at com.typesafe.config.impl.SimpleConfig.getInt(SimpleConfig.java:190)
at com.attensity.middleware.actor.AbcActor.createSearchHandlers(AbcActor.java:178)
at com.attensity.middleware.actor.AbcActor.createChildActors(AbcActor.java:135)
at com.attensity.middleware.actor.AbcActor.<init>(AbcActor.java:100)
... 18 more

[ERROR] [10/20/2014 21:25:18.741] [Abc-akka.actor.db-dispatcher-7] [akka://Abc/user/AbcActor/StatusSyncActor] Started statusSyncActor


--------------------------------------------------------------------------------

case 2:

application.conf:

akka {
  actor {
    db-dispatcher {
      type = Dispatcher
       ......
    }

    deployment {
       // other actors here, but not StatusSyncActor
   }
 }
}

AbcActor.java:
        context().actorOf(RedisStatusSyncActor.props(configuration, statusRedisConfiguration, eventBus).withDispatcher("akka.actor.db-dispatcher"), StatusSyncActor);


Log:

2014-10-20 20:48:41,969 [Middleware-akka.actor.default-dispatcher-4] INFO  c.a.m.r.actor.RedisStatusSyncActor - Started RedisStatusSyncActor
2014-10-20 20:48:41,970 [Middleware-akka.actor.default-dispatcher-4] INFO  c.a.m.r.actor.RedisStatusSyncActor - getContext().props().dispatcher() is akka.actor.db-dispatcher, context().dispatcher() is Dispatcher[akka.actor.db-dispatcher]
2014-10-20 20:48:41,981 [Middleware-akka.actor.default-dispatcher-4] INFO  c.a.m.r.actor.RedisStatusSyncActor - Starting sync

----------------------------------------------------------------
case 3:
 
akka {
  actor {
    db-dispatcher {
      type = Dispatcher
      ....
    }

    deployment {
      /AbcActor/StatusSyncActor {
        dispatcher = akka.actor.db-dispatcher
      }
  }
 }
}

AbcActor.java:

        context().actorOf(RedisStatusSyncActor.props(configuration, statusRedisConfiguration, eventBus), STATUS_SYNC_ACTOR);

Log:

2014-10-20 20:33:22,136 [Abc-akka.actor.default-dispatcher-2] INFO  c.a.s.r.actor.RedisStatusSyncActor - Started RedisStatusSyncActor
2014-10-20 20:33:22,222 [Abc-akka.actor.default-dispatcher-11] INFO  c.a.s.r.actor.RedisStatusSyncActor - getContext().props().dispatcher() is akka.actor.db-dispatcher, context().dispatcher() is Dispatcher[akka.actor.db-dispatcher]
2014-10-20 20:33:22,224 [Abc-akka.actor.default-dispatcher-11] INFO  c.a.s.r.actor.RedisStatusSyncActor - Starting sync


Thanks,
L

Patrik Nordwall

unread,
Oct 21, 2014, 10:18:06 AM10/21/14
to akka...@googlegroups.com
It looks like you use SLF4J logging. The thread you see in the log is not the thread of the actor that emitted the log event. You must use the %X{akkaSource} variable in the logging pattern to see that. See: http://doc.akka.io/docs/akka/2.3.6/scala/logging.html#Logging_Thread_and_Akka_Source_in_MDC

Please verify that and let me know if it is still a problem after that.

/Patrik


You can also verify by using the default logging, i.e. remove loggers = ["akka.event.slf4j.Slf4jLogger"]

Patrik Nordwall
Typesafe Reactive apps on the JVM
Twitter: @patriknw

lakshmi gopalan

unread,
Oct 21, 2014, 3:14:17 PM10/21/14
to akka...@googlegroups.com
Patrick, 

That worked!! Thank you so much. I removed the default logging by Slf4jLogger, and also changed the logging pattern!

It was in fact using the custom dispatcher. Phew!

Thanks again for your help!

L

You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/WOcUc-bIc60/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

Patrik Nordwall

unread,
Oct 21, 2014, 3:33:43 PM10/21/14
to akka...@googlegroups.com
You're welcome. Happy hAkking!

/Patrik
Reply all
Reply to author
Forward
0 new messages