Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the number of queued jobs of a particular type in gearman?

Tags:

php

gearman

I have a number of gearman clients sending a job, say job1.

$client = new GearmanClient();
$client->addServer();
$client->doBackground('job1', 'workload');

It takes, say 10 seconds to process this job. I want to track how many 'job1' jobs are waiting for a worker to work on them at any given time. How can I do that?

like image 633
Coffee Bite Avatar asked Jul 31 '10 15:07

Coffee Bite


2 Answers

For quick checking, I use this bash one-liner:

(echo status ; sleep 0.1) | netcat 127.0.0.1 4730

This opens a connection to a gearman instance running on localhost, and sends the status query. This contains the name and number of jobs on that instance. The information can then be processed with grep/awk/wc etc. for reporting and alerting.

I also do the same with the workers query which shows all connected workers.

(echo workers ; sleep 0.1) | netcat 127.0.0.1 4730

The sleep is to keep the connection open long enough for the reply.

The full list of administrative commands, and what the output means is at http://gearman.org/protocol/. Just search for "Administrative Protocol".

like image 53
d5ve Avatar answered Oct 18 '22 21:10

d5ve


To expand on d5ve's answer, add a -w parameter to "time out" your netcat connection, otherwise you never get back to a command prompt.

$ (echo status ; sleep 0.1) | sudo netcat 127.0.0.1 4730 -w 1
like image 35
iandouglas Avatar answered Oct 18 '22 19:10

iandouglas