run_observer 68 5 5
run_observer 11 4 6
run_observer 65 10 10
So, depending upon which worker I ask, I have anywhere from 11 - 68 jobs queued, 4 - 10 jobs running (It should be more like 14), and 21 available workers. Basically, none of these numbers make sense no matter how I interpret them, and shouldn't they be in sync?
Am I completely misunderstanding how the worker servers are supposed to be setup in a multi-server environment?
As far as I can tell, jobs ARE being distributed to different workers. It's just that the utilization and stats seem far off from what I'm expecting.
The results of gearadmin --workers are similarly skewed. It should be noted however, that when I run this command I DO see the private IP of all three worker servers listed, albeit with significantly varying distributions.
Enter code here... /**
* Start gearman worker
*/
public function gearmanWorkerAction()
{
set_error_handler([$this,'errHandle']);
register_shutdown_function([$this,'fatalErrorShutdownHandler']);
$this->_start_version = filemtime(realpath(APPLICATION_PATH . DIRECTORY_SEPARATOR . '..'));
$this->_worker_start_time = time();
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$worker= new \GearmanWorker();
foreach($this->_getWorkerServers() as $worker_server){
$worker->addServer($worker_server[0],$worker_server[1]);
}
$worker->addFunction("run_observer", array($this,"run_observer"));
while ($worker->work());
}
/**
* Queue any tasks that need to be run by gearman worker. This should be on a cron job.
*/
public function gearmanClientAction()
{
$client = new GearmanClient();
foreach($this->_getWorkerServers() as $worker_server){
$client->addServer($worker_server[0],$worker_server[1]);
}
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$this->_checkSubmittedTasks($client);
/**
* Make sure all scheduled jobs configured in .ini files are registered in the database
*/
$this->_registerConfiguredGearmanTasks();
$gearman_tasks = $this->getEntityManager()->getRepository('\Ia\Entity\GearmanTask')->getTasksToRun();
if(count($gearman_tasks)>0){
/**
* Register callbacks
*/
$client->setStatusCallback(array($this,'_gearmanTaskStatus'));
$client->setDataCallback(array($this,'_gearmanTaskData'));
$client->setCreatedCallback(array($this,'_gearmanTaskCreated'));
$client->setCompleteCallback(array($this,'_gearmanTaskComplete'));
$client->setExceptionCallback(array($this,'_gearmanTaskException'));
$client->setFailCallback(array($this,'_gearmanTaskFail'));
foreach($gearman_tasks as $gearman_task){
if($gearman_task->priority == \Ia\Entity\GearmanTask::PRIORITY_HIGH
|| APPLICATION_ENV == 'production'){
$gearman_task->setState(\Ia\Entity\GearmanTask::STATE_SUBMITTED);
$workload = serialize(array($gearman_task->resource,unserialize($gearman_task->params)));
$unique_id = ($gearman_task->type==\Ia\Entity\GearmanTask::TYPE_SCHEDULED) ? $gearman_task->id.'_'.$gearman_task->next_run : $gearman_task->id;
switch($gearman_task->priority){
case \Ia\Entity\GearmanTask::PRIORITY_HIGH:
$client->addTaskHigh("run_observer", $workload, null, $unique_id);
break;
case \Ia\Entity\GearmanTask::PRIORITY_LOW:
$client->addTaskLow("run_observer", $workload, null, $unique_id);
break;
default:
$client->addTask("run_observer", $workload, null, $unique_id);
break;
}
$this->getEntityManager()->persist($gearman_task);
$this->getEntityManager()->flush();
}
}
$client->runTasks();
}
}
protected function _getWorkerServers()
{
if(count($this->_worker_servers)==0){
if(\Ia\Config::get('gearman_worker/servers')){
foreach(\Ia\Config::get('gearman_worker/servers') as $worker_server){
$parts = explode(':',$worker_server);
if(count($parts)==2){
$this->_worker_servers[] = $parts;
}
}
}
if(count($this->_worker_servers)==0){
$this->_worker_servers[] = ['127.0.0.1', 4730];
}
}
shuffle($this->_worker_servers);
return $this->_worker_servers;
}
Excerpts from Aaron Lozier's message of 2017-05-03 12:29:13 -0700:
> Enter code here...
>
> I really appreciate you taking the time to respond. Your description of the
> "deafening silence" surrounding Gearman is an apt one. I feel like I have
> read everything that has been written about Gearman, desperate to find some
> clarity. For better or for worse, I have invested a huge amount of time and
> energy into implementing Gearman into our application. It would be one
> thing if it was failing for me completely, but it's much more subtle than
> that. The actual situation I've been dealing with is that upon a full
> reboot of all worker servers, everything works flawlessly - for awhile. It
> seems around the 2-3 day mark that cracks start appearing. And the symptoms
> are varied. I forgot to mention another problem: sometimes workers sit in
> the queue for a very long time before beginning to run. Actually that could
> be related to my #1 above.
>
Indeed. We're trying to bring it back, slowly. Great to have you here
and interested. :)
Have you tried 1.1.15?
root@worker2:~# lsof -p `pidof gearmand` | fgrep TCP
gearmand 794 gearman 9u IPv4 8173 0t0 TCP *:4730 (LISTEN)
gearmand 794 gearman 10u IPv6 8174 0t0 TCP *:4730 (LISTEN)
gearmand 794 gearman 33u IPv4 294742 0t0 TCP 10.138.240.28:4730->10.138.112.183:55239 (ESTABLISHED)
gearmand 794 gearman 34u IPv4 2058447 0t0 TCP 10.138.240.28:4730->10.138.112.183:55463 (ESTABLISHED)
gearmand 794 gearman 35u IPv4 556773 0t0 TCP 10.138.240.28:4730->10.138.112.183:57352 (ESTABLISHED)
gearmand 794 gearman 36u IPv4 1226662 0t0 TCP 10.138.240.28:4730->10.138.112.183:43889 (ESTABLISHED)
gearmand 794 gearman 37u IPv4 1803366 0t0 TCP 10.138.240.28:4730->10.138.112.183:37649 (ESTABLISHED)
gearmand 794 gearman 38u IPv4 796462 0t0 TCP 10.138.240.28:4730->10.138.112.183:60539 (ESTABLISHED)
gearmand 794 gearman 39u IPv4 61229 0t0 TCP 10.138.240.28:4730->10.138.112.183:55998 (ESTABLISHED)
gearmand 794 gearman 40u IPv4 37213 0t0 TCP 10.138.240.28:4730->10.138.112.183:54403 (ESTABLISHED)
gearmand 794 gearman 41u IPv4 1097150 0t0 TCP 10.138.240.28:4730->10.138.112.183:33877 (ESTABLISHED)
gearmand 794 gearman 42u IPv4 1629211 0t0 TCP 10.138.240.28:4730->10.138.112.183:51950 (ESTABLISHED)
gearmand 794 gearman 43u IPv4 102537 0t0 TCP 10.138.240.28:4730->10.138.112.183:60353 (ESTABLISHED)
gearmand 794 gearman 44u IPv4 1059021 0t0 TCP 10.138.240.28:4730->10.138.112.183:59459 (ESTABLISHED)
gearmand 794 gearman 45u IPv4 2059753 0t0 TCP 10.138.240.28:4730->10.138.112.183:58456 (ESTABLISHED)
gearmand 794 gearman 46u IPv4 52910 0t0 TCP 10.138.240.28:4730->10.138.112.183:55176 (ESTABLISHED)
gearmand 794 gearman 47u IPv4 1516057 0t0 TCP 10.138.240.28:4730->10.138.240.28:58078 (ESTABLISHED)
gearmand 794 gearman 48u IPv4 2072308 0t0 TCP 10.138.240.28:4730->10.138.112.183:37881 (ESTABLISHED)
gearmand 794 gearman 49u IPv4 1516042 0t0 TCP 10.138.240.28:4730->10.138.112.183:34500 (ESTABLISHED)
gearmand 794 gearman 50u IPv4 2037465 0t0 TCP 10.138.240.28:4730->10.138.112.183:40807 (ESTABLISHED)
gearmand 794 gearman 52u IPv4 2065869 0t0 TCP 10.138.240.28:4730->10.138.0.156:52906 (ESTABLISHED)
gearmand 794 gearman 53u IPv4 2066152 0t0 TCP 10.138.240.28:4730->10.138.0.156:52923 (ESTABLISHED)
gearmand 794 gearman 54u IPv4 2054916 0t0 TCP 10.138.240.28:4730->10.138.112.183:55065 (ESTABLISHED)
gearmand 794 gearman 55u IPv4 1654587 0t0 TCP 10.138.240.28:4730->10.138.112.183:53906 (ESTABLISHED)
gearmand 794 gearman 56u IPv4 1541322 0t0 TCP 10.138.240.28:4730->10.138.112.183:38534 (ESTABLISHED)
gearmand 794 gearman 57u IPv4 11177 0t0 TCP 10.138.240.28:4730->10.138.0.156:38832 (ESTABLISHED)
gearmand 794 gearman 58u IPv4 26468 0t0 TCP 10.138.240.28:4730->10.138.112.183:53051 (ESTABLISHED)
gearmand 794 gearman 59u IPv4 1342442 0t0 TCP 10.138.240.28:4730->10.138.112.183:49107 (ESTABLISHED)
gearmand 794 gearman 60u IPv4 32813 0t0 TCP 10.138.240.28:4730->10.138.112.183:53783 (ESTABLISHED)
gearmand 794 gearman 61u IPv4 1946294 0t0 TCP 10.138.240.28:4730->10.138.112.183:42830 (ESTABLISHED)
gearmand 794 gearman 63u IPv4 1687104 0t0 TCP 10.138.240.28:4730->10.138.112.183:55248 (ESTABLISHED)
gearmand 794 gearman 64u IPv4 1630342 0t0 TCP 10.138.240.28:4730->10.138.240.28:47814 (ESTABLISHED)
gearmand 794 gearman 65u IPv4 190775 0t0 TCP 10.138.240.28:4730->10.138.112.183:43088 (ESTABLISHED)
gearmand 794 gearman 66u IPv4 2031486 0t0 TCP 10.138.240.28:4730->10.138.112.183:38689 (ESTABLISHED)
gearmand 794 gearman 67u IPv4 2063770 0t0 TCP 10.138.240.28:4730->10.138.112.183:60613 (ESTABLISHED)
gearmand 794 gearman 68u IPv4 1685918 0t0 TCP 10.138.240.28:4730->10.138.240.28:57036 (ESTABLISHED)
gearmand 794 gearman 69u IPv4 1993026 0t0 TCP 10.138.240.28:4730->10.138.112.183:37511 (ESTABLISHED)
gearmand 794 gearman 70u IPv4 2073329 0t0 TCP 10.138.240.28:4730->10.138.240.28:55105 (ESTABLISHED)
gearmand 794 gearman 71u IPv4 2047229 0t0 TCP 10.138.240.28:4730->10.138.240.28:52196 (ESTABLISHED)
gearmand 794 gearman 73u IPv4 2066159 0t0 TCP 10.138.240.28:4730->10.138.0.156:52927 (ESTABLISHED)
gearmand 794 gearman 74u IPv4 1856009 0t0 TCP 10.138.240.28:4730->10.138.112.183:58012 (ESTABLISHED)
gearmand 794 gearman 75u IPv4 1815629 0t0 TCP 10.138.240.28:4730->10.138.0.156:50528 (ESTABLISHED)
gearmand 794 gearman 76u IPv4 2066170 0t0 TCP 10.138.240.28:4730->10.138.112.183:33272 (ESTABLISHED)
gearmand 794 gearman 77u IPv4 2024398 0t0 TCP 10.138.240.28:4730->10.138.112.183:55905 (ESTABLISHED)
gearmand 794 gearman 78u IPv4 2073037 0t0 TCP 10.138.240.28:4730->10.138.112.183:35879 (ESTABLISHED)
gearmand 794 gearman 79u IPv4 1962985 0t0 TCP 10.138.240.28:4730->10.138.112.183:44088 (ESTABLISHED)
gearmand 794 gearman 80u IPv4 2059882 0t0 TCP 10.138.240.28:4730->10.138.112.183:58833 (ESTABLISHED)
gearmand 794 gearman 81u IPv4 2073353 0t0 TCP 10.138.240.28:4730->10.138.112.183:36764 (ESTABLISHED)
gearmand 794 gearman 82u IPv4 2000079 0t0 TCP 10.138.240.28:4730->10.138.0.156:51981 (ESTABLISHED)
gearmand 794 gearman 83u IPv4 2070961 0t0 TCP 10.138.240.28:4730->10.138.0.156:52936 (ESTABLISHED)
gearmand 794 gearman 84u IPv4 2066311 0t0 TCP 10.138.240.28:4730->10.138.112.183:33604 (ESTABLISHED)
gearmand 794 gearman 85u IPv4 2071678 0t0 TCP 10.138.240.28:4730->10.138.112.183:34495 (ESTABLISHED)
gearmand 794 gearman 86u IPv4 2070970 0t0 TCP 10.138.240.28:4730->10.138.0.156:52938 (ESTABLISHED)