ClusterSingleton guaranteed to be single threaded?


If I create a cluster singleton like below

 ActorSystem system = ActorSystem.create("ClusterSystem", config);
      ClusterSingletonManagerSettings settings = ClusterSingletonManagerSettings.create(system)
          Props.create(StatsService.class), PoisonPill.getInstance(), settings),

Is it guaranteed that only one copy of the StatsService actor exists and will be single threaded?

(Johan Andrén) #2

There will only be one instance, but it will not be single threaded, however, it will only ever process a message on one thread at a time, and can safely keep mutable state - just like any actor.

If you need to dedicate a thread to the singleton, for example you have some library that needs the thread to be the same at all times for some reason, you will need to use a pinned dispatcher for it.


If the cluster singleton (like stats service in the example above), is holding an instance to a cache store

Jedis jedis = new Jedis("", 6379);

Is it safer instead to use a connection pool or it doesn’t matter?

JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost");

(Patrik Nordwall) #4

It should be enough to use one connection since the actor will process one message at a time, sequentially.