关于task进程阻塞,task_ipc_mode' => 3,任务处理情况的问题

例程就是源码examples/server.php做了点改动

$serv->set(array( 'worker_num' => 1, //'open_eof_check' => true, //'package_eof' => "\r\n", //'ipc_mode' => 2, 'task_worker_num' => 5, 'task_ipc_mode' => 3, //'dispatch_mode' => 1, //'daemonize' => 1, //'log_file' => '/tmp/swoole.log', //'heartbeat_check_interval' => 10, ));

......

$serv_bak=null;

function my_onWorkerStart($serv, $worker_id) { global $argv; if($worker_id >= $serv->setting['worker_num']) { swoole_set_process_name("php {$argv[0]}: task"); } else { swoole_set_process_name("php {$argv[0]}: worker"); } echo "WorkerStart: MasterPid={$serv->master_pid}|Manager_pid={$serv->manager_pid}"; echo "|WorkerId={$serv->worker_id}|WorkerPid={$serv->worker_pid}\n";

global $serv_bak;
$serv_bak=$serv;

if($worker_id >= $serv->setting['worker_num']+3)
{
    $gmworker= new GearmanWorker();
    $gmworker->addServer();

    $gmworker->addFunction("jfytest", "my_WorkerTest");

    echo "Waiting for job...\n";
    //task进程会阻塞在work()函数这里
    while($gmworker->work())
    {
      if ($gmworker->returnCode() != GEARMAN_SUCCESS)
      {
        echo "return_code: " . $gmworker->returnCode() . "\n";
        exit;
      }
    }
}

}

WorkerStart: MasterPid=10259|Manager_pid=10261|WorkerId=0|WorkerPid=10263 WorkerStart: MasterPid=10259|Manager_pid=10261|WorkerId=1|WorkerPid=10264 WorkerStart: MasterPid=10259|Manager_pid=10261|WorkerId=2|WorkerPid=10265 WorkerStart: MasterPid=10259|Manager_pid=10261|WorkerId=3|WorkerPid=10266 WorkerStart: MasterPid=10259|Manager_pid=10261|WorkerId=4|WorkerPid=10267 WorkerStart: MasterPid=10259|Manager_pid=10261|WorkerId=5|WorkerPid=10268

一个worker进程 五个tasker进程

其中后两个task进程会以服务的方式监听gearman,会阻塞在work()函数那里

客户端telnet提交taskwait请求:

10263 Worker#10263 Client[32@0]: received: taskwait

AsyncTask[PID=10264]: task_id=0. SyncTask: result=Task OK

10263 Worker#10263 Client[32@0]: received: taskwait

AsyncTask[PID=10265]: task_id=1. SyncTask: result=Task OK

10263 Worker#10263 Client[32@0]: received: taskwait

AsyncTask[PID=10266]: task_id=2. SyncTask: result=Task OK

10263 Worker#10263 Client[32@0]: received: taskwait

PHP Warning: swoole_server::taskwait(): taskwait failed. Error: Inappropriate ioctl for device[25] in /home/jfy/testprog/server2.php on line 149 SyncTask: result=

10263 Worker#10263 Client[32@0]: received: taskwait

PHP Warning: swoole_server::taskwait(): taskwait failed. Error: Inappropriate ioctl for device[25] in /home/jfy/testprog/server2.php on line 149 SyncTask: result=

10263 Worker#10263 Client[32@0]: received: taskwait

AsyncTask[PID=10264]: task_id=5. SyncTask: result=Task OK

这感觉不象是争抢模式啊,好象是轮循模式啊

而且到第4个taskwait时,出错了 第5个继续出错 第6个又正常了 第7个又是第一个task进程接收处理了

这是争抢模式吗?

2014-11-04 16:37
0

要回复问题请先登录注册