【发布时间】:2015-04-01 16:46:45
【问题描述】:
Gearman 客户端在添加作业时随机超时。我无法重新创造导致失败的条件。 Gearman 守护进程正在运行!
条件:上传一批要排队的文件到Gearman进行大小调整。我可以上传数百个而不会出错。但是,每隔一段时间,单个作业将无法提交,并出现以下错误:
gearman_wait(GEARMAN_TIMEOUT) timeout reached,
1 servers were poll(), no servers were available, pipe:false ->
libgearman/universal.cc:328
但是,在失败作业之前和之后立即提交的作业都会通过!我什至可以重新上传相同的图像,并在第二次尝试时通过。 gearman 服务器在那里...这是某种与 gearmand 或 php-pecl-gearman 扩展有关的故障吗??
齿轮配置:
OPTIONS="
--port=4730 \
--verbose=NOTICE \
--log-file=/var/log/gearman/gearmand.log \
--keepalive \
--threads=4 \
--queue-type=MySQL \
--mysql-host=localhost \
--mysql-port=xxx \
--mysql-user=xx \
--mysql-password=xx \
--mysql-db=xxxD \
--mysql-table=gearman_queue \
--job-retries=5"
PHP Gearman 扩展 (PECL)
gearman support => enabled
extension version => 1.1.2
libgearman version => 1.1.8
Default TCP Host => localhost
Default TCP Port => 4730
日志显示所有接受的作业,没有记录失败的作业
NOTICE 2015-02-02 16:25:54.000000 [ proc ] accepted,worker_name,jobidprefix65468823354cfa51234fa09.3540767125336,0 -> libgearman-server/server.cc:314
NOTICE 2015-02-02 16:25:56.000000 [ proc ] accepted,worker_name,jobidprefix40605707054cfa51438b0d0.383048589216,0 -> libgearman-server/server.cc:314
NOTICE 2015-02-02 16:25:56.000000 [ proc ] accepted,worker_name,jobidprefix197198183754cfa51447dac9.5387112932157,0 -> libgearman-server/server.cc:314
在提交作业之前,我什至 ping 了该死的 gearman 服务器以确保它在那里! Ping 结果是真的!!
$gmclient= new GearmanClient();
$gmclient->addServer("127.0.0.1", ((int)$gearmanPort)); # Add default server (localhost).
$gmclient->setTimeout(300);//set timeout to send gearman errors
//assign a unique id for the job (limit the length to prevent db errors)
$uniqueid = substr('jobPrefix'.uniqid (rand (),true).rand(0, 32767), 0, 63);
//add the job to the background
$job_handle = $gmclient->addTaskBackground("worker_name", $jobdata, null, $uniqueid);
//ping gearman to make sure it is working before sending job
//keep trying for 2 seconds (4 times per second) until success or failure
$pingCount = 1;
while (@$gmclient->ping(serialize("Ping Test")) === FALSE && $pingCount <= 8) {
$this->log('Couldnt ping gearman server on pingCount='.$pingCount.'/8');
usleep(250000); //sleep for 0.25 seconds before trying again
$pingCount++;
}
//queue the job
if (@!$gmclient->runTasks()) //supress gearman fatal errors so we can catch them
{
throw new CHttpException(500,"ERROR " . $gmclient->error());
}
if (@$gmclient->returnCode() != GEARMAN_SUCCESS) //supress gearman fatal errors so we can catch them
{
throw new CHttpException(500,'ERROR: Bad return code for brokenlinkcheck '.$gmclient->returnCode());
}
【问题讨论】: