如何使用ZooKeeper设计任务分配

发布于 2024-10-21 04:02:37 字数 253 浏览 7 评论 0原文

我计划编写一个具有分布式工作进程的应用程序。其中之一将是领导者,它将任务分配给其他进程。设计 Leader 选举过程非常简单:每个过程都尝试在同一路径中创建一个临时节点。谁成功了,谁就成为领导者。

现在,我的问题是如何设计均匀分配任务的流程?有什么食谱吗?

我将详细说明一下环境设置:

假设有 10 台工作机,每台运行一个进程,其中一台成为领导者。任务在队列中提交,Leader 接收它们并分配给工作人员。每当提交任务时,工作进程都会收到通知。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光礼记 2024-10-28 04:02:37

我不确定我是否理解您的领导者选举算法,但推荐的实现方法是使用顺序临时节点并使用 http://zookeeper.apache.org/doc/r3.3.3/recipes.html#sc_leaderElection 解释了如何避免“羊群”效应。

任务的分发可以通过简单的分布式队列来完成,并不严格需要 Leader。生产者将任务排队,消费者监视任务节点 - 触发的监视将导致消费者接受任务并删除关联的 znode。对失败的消费者重新排队任务时需要考虑某些边缘条件。 http://zookeeper.apache.org/doc/r3.3.3/recipes .html#sc_recipes_Queues

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

带上头具痛哭 2024-10-28 04:02:37

我会推荐这本书的示例:Master-Worker应用程序部分ZooKeeper分布式进程协调http://shop.oreilly.com/product/0636920028901.do

该示例演示了如何使用 znode 和常见的 Zookeeper 命令将任务分发给工作人员。

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.

烂人 2024-10-28 04:02:37

考虑使用参与者单例服务模式。例如,在 Scala 中,有 Akka 可以用更少的代码解决此类问题。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文