scala - Service with background jobs, how to ensure jobs only run periodically ONCE per cluster -


i have play framework based service stateless , intended deployed across many machines horizontal scaling.

this service handling http json requests , responses, , using couchdb data store again maximum scalability.

we have small number of background jobs need run every x seconds across whole cluster. vital jobs not execute concurrently on each machine.

to execute jobs we're using actors , akka scheduler (since we're using scala):

akka.system().scheduler.schedule(     duration.create(0, timeunit.milliseconds),         duration.create(10, timeunit.seconds),         akka.system().actorof(loggingjob.props),         "tick") 

(etc)

object loggingjob {     def props = props[loggingjob] }  class loggingjob extends untypedactor {     override def onreceive(message: any) {         logger.info("job executed! " + message.tostring())     } } 

is there:

  • any built in trickery in akka/actors/play i've missed me?
  • or recognised algorithm can put on top of couchbase (distributed mutex? not quite?) this?

i not want make of instances 'special' needs simple deploy , manage.

check out akka's cluster singleton pattern.

for use cases convenient , mandatory ensure have 1 actor of type running somewhere in cluster.

some examples:

  • single point of responsibility cluster-wide consistent decisions, or coordination of actions across cluster system
  • single entry point external system
  • single master, many workers
  • centralized naming service, or routing logic

using singleton should not first design choice. has several drawbacks, such single-point of bottleneck. single-point of failure relevant concern, cases feature takes care of making sure singleton instance started.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -