【问题标题】:How to divide workers and aggregate results?如何划分工人和汇总结果?
【发布时间】:2016-06-16 17:26:40
【问题描述】:

给定一个提交给 parentWorker 的有效负载:

  1. 我将工作分配给 otherWorkers,并将 parentWorker 的 taskId 作为附加属性添加到负载中
  2. 其他每个工人都完成了他们负责的工作

我想知道是否有 5 个或 10 个或 20 个 otherWorkers 排队/开始,那么他们什么时候完成?因为当所有这些都完成后,我想开始我的工作流程的下一部分:nextWorker!

所以理想的管道是:parentWorker > X # of otherWorkers > everyone done? > nextWorker

我怎样才能做到这一点?

请不要使用基于轮询的解决方案来回答。我不是在找那个。

我想过使用缓存:

  1. parentWorker 将设置将创建的 otherWorkers 的总数,例如:cachekey_<parertTaskId>_workersCreated: 10
  2. 那么 otherWorkers 将在完成后自动将 # 递减 -1,最终计数将达到零:cachekey_<parertTaskId>_workersCreated: 0 但应该由谁来处理该计数?

a) 如果想法是让 otherWorkers 递减它,那么检查该值并查看它是否为零并启动 nextWorker ...在以下情况下存在缺陷:

cachekey_<parertTaskId>_workersCreated: 2
otherWorker9 sends -1
otherWorker10 sends -1
otherWorker9 checks and otherWorker10 checks
both get back 0 and both will kick off nextWorker! We only wanted one instance.

b) 其他坏主意:

cachekey_<parertTaskId>_workersCreated: 2
otherWorker9 checks and otherWorker10 checks
neither one kicks off nextWorker because value!==1
otherWorker9 sends -1
otherWorker10 sends -1
its over and noone is left to act on cachekey_<parertTaskId>_workersCreated: 0

【问题讨论】:

    标签: distributed iron.io ironworker


    【解决方案1】:

    不幸的是,没有自动化/非常简单/内置的方法可以做到这一点。

    关于你使用缓存的想法,如果你使用 Redis 之类的东西,它的递增和递减操作是原子的,所以你永远不会遇到两个工作人员都返回相同数字的情况。一名工人和一名工人只能得到零:http://redis.io/commands/decr

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 2016-11-22
      • 2021-12-08
      • 2015-06-27
      • 2011-09-30
      • 1970-01-01
      相关资源
      最近更新 更多