-
Notifications
You must be signed in to change notification settings - Fork 83
Description
This is a problem if you want to limit the amount of "functions" run concurrently, ie. if you want to run one job at a time.
What happens is the worker continuously accepts jobs from the server while only running running n at time (worker.New(n) where n not equal to 0). The major problem with this is those jobs cannot be run by other workers, thus losing a lot of the power of gearman. Also pinging the server for job status will says all the locally queued jobs are running, when only n are (see example below).
Given this limitation, this code should not be used. I was unable to fix this in an elegant way as the nature of the implementation has a bunch of stuff going on concurrently and was unable to put in a nice fix to limit things.
I recommend simplifying everything so one worker has one connection to each gearman server and can only do one job at a time. If you need to run multiple functions at a time then create multiple workers
How to reproduce
- Have a a local gearman server running the this go package installed
- Run this code to queue up 100 background jobs https://gist.github.com/paulmach/5445876
- run
(echo status ; sleep 0.1) | nc 127.0.0.1 4730on the console to see what is queued on the gearman server. You should see
test 100 0 0
.
This means 100 test jobs queued, 0 running, and 0 workers connected who can do this job.
- Run the test worker to process these jobs https://gist.github.com/paulmach/5445970
- This should run one job at a time and take a while to complete as each job is a 2 second sleep
- While the above is running, run
(echo status ; sleep 0.1) | nc 127.0.0.1 4730in another terminal. You should see something like
test 97 19 1
.
This means 97 jobs are still waiting to complete, 19 are running and there is 1 worker working.
- THIS IS THE PROBLEM. the one testworker.go has 19 jobs assigned to it but is only doing one at a time. If another worker comes along, it will not get these 19 jobs. Also pinging the server for job status will say these 19 jobs are running when in fact only 1 is.