How to design task distribution with ZooKeeper
Asked Answered
B

3

12

I am planning to write an application which will have distributed Worker processes. One of them will be Leader which will assign tasks to other processes. Designing the Leader elelection process is quite simple: each process tries to create a ephemeral node in the same path. Whoever is successful, becomes the leader.

Now, my question is how to design the process of distributing the tasks evenly? Any recipe for this?

I'll elaborate a little on the environment setup:

Suppose there are 10 worker maschines, each one runs a process, one of them become leader. Tasks are submitted in the queue, the Leader takes them and assigns to a worker. The worker processes gets notified whenever a tasks is submitted.

Baez answered 7/3, 2011 at 9:13 Comment(0)
O
9

I am not sure I understand your algorithm for Leader election, but the recommended way of implementing this is to use sequential ephemeral nodes and use the algorithm at http://zookeeper.apache.org/doc/r3.3.3/recipes.html#sc_leaderElection which explains how to avoid the "herd" effect.

Distribution of tasks can be done with a simple distributed queue and does not strictly need a Leader. The producer enqueues tasks and consumers keep a watch on the tasks node - a triggered watch will lead the consumer to take a task and delete the associated znode. There are certain edge conditions to consider with requeuing tasks from failed consumers. http://zookeeper.apache.org/doc/r3.3.3/recipes.html#sc_recipes_Queues

Oiler answered 17/6, 2011 at 15:0 Comment(0)
S
1

I would recommend the section Example: Master-Worker Application of this book ZooKeeper Distributed Process Coordination http://shop.oreilly.com/product/0636920028901.do

The example demonstrates to distribute tasks to worker using znodes and common zookeeper commands.

Selfridge answered 14/5, 2015 at 8:13 Comment(0)
B
0

Consider using an actor singleton service pattern. For example, in Scala there is Akka which solves this class of problem with less code.

Brython answered 23/5, 2012 at 12:35 Comment(1)
Question is specifically related to ZooKeeper. Then why are you suggesting him all together different solution?Antonioantonius

© 2022 - 2024 — McMap. All rights reserved.