Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zx19981 opened this issue Apr 16, 2018 · 2 comments
Open

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

zx19981 opened this issue Apr 16, 2018 · 2 comments

Comments

@zx19981
Copy link

zx19981 commented Apr 16, 2018

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

@mikespook
Copy link
Owner

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

@zx19981
Copy link
Author

zx19981 commented Apr 19, 2018

@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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants