gearman-go icon indicating copy to clipboard operation
gearman-go copied to clipboard

worker连续两次grab会导致获取不到任务

Open zx19981 opened this issue 7 years ago • 2 comments

请问: 1 worker连续两次grab: a.Grab() a.Grab() 获取到一个任务后再也获取不到任务了,为什么,是Job Server限制了吗? 2 worker里面一个agent是不是不支持并发,必须grab到一个任务后,再grab下一个? 3 注册多个AddFunc后,观察发现Job Server是按照注册的反序发送任务的,即必须等后面注册的全部拉空后才能获取到前面注册的任务? 期待您的回答,谢谢!

zx19981 avatar Apr 16 '18 10:04 zx19981

agent 是用于维持 gearman 的连接的。由于 gearman 的协议设计(任务没有 UUID),无法并发的处理多个任务。对于延迟敏感的应用,我建议使用 MQ 来代替 gearman。例如利用 MQTT 作为基础协议重新设计这部分功能,来代替 gearman。

mikespook avatar Apr 18 '18 00:04 mikespook

@mikespook,非常感谢您的回复!

根据gearman的协议: JOB_ASSIGN

This is given in response to a GRAB_JOB request to give the worker
information needed to run the job. All communication about the
job (such as status updates and completion response) should use
the handle, and the worker should run the given function with
the argument.

Arguments:
**- NULL byte terminated job handle.**
- NULL byte terminated function name.
- Opaque data that is given to the function as an argument.

这里的"handle"不是UUID吗,并且 func (worker *Worker) handleInPack(inpack *inPack) { switch inpack.dataType { case dtNoJob: inpack.a.PreSleep() case dtNoop: inpack.a.Grab() case dtJobAssign, dtJobAssignUniq: go func() { if err := worker.exec(inpack); err != nil { worker.err(err) } }() worker是支持并发的啊,是否只是gearman在服务端做了控制,一个连接拉取任务是串行的,即:

  1. GRAB_JOB
  2. JOB_ASSIGN
  3. GRAB_JOB
  4. JOB_ASSIGN

而不支持

  1. GRAB_JOB
  2. GRAB_JOB
  3. JOB_ASSIGN
  4. JOB_ASSIGN

再次期待您的回答,谢谢!

zx19981 avatar Apr 19 '18 06:04 zx19981