Jobs execute in order of functions added, then priority

Bug #1067503 reported by Doug Harple on 2012-10-16
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Brian Aker

Bug Description

When determining which job to run next, it appears that the worker does the following:

1) Iterates over functions in the order in which they were added.
2) For each function, it pulls the highest priority available job, in the order that the job was added.

This behavior confused me at first, and led me to believe that the prioritization system was broken.

The behavior I expected was that it would pull the highest priority job from the set of functions added to the worker.

(If this is working as designed, that's OK, I can work around it. I couldn't find anything in the documentation regarding the behavior.)

Doug Harple (dharple) wrote :

For example, I have a single worker that listens for functions a() and b():

$worker = new GermanWorker();
$worker->addFunction('a', 'a');
$worker->addFunction('b', 'b');
while ($worker->work());

I stop the worker, and I then run a client that does the following:

$client = new GearmanClient();
$client->doHighBackground('b', 'whatever');
$client->doLowBackground('a', 'whatever');

If I then start the worker, it will run the low priority task before the high priority task, due to the order in which the functions were added to the worker.

Brian Aker (brianaker) wrote :

I need to dig through the code. This was switched at one point and I can no longer remember why.

Changed in gearmand:
assignee: nobody → Brian Aker (brianaker)
status: New → Confirmed
Clint Byrum (clint-fewbar) wrote :

I added the --round-robin option a while back, but we had round robin mode off by default because of your concerns that people might be expecting the (rather insidious) "drain the last one registered completely" behavior.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers