Gearman slow when client sends large payload Gearman slow when client sends large payload php php

Gearman slow when client sends large payload


Check whether this code works for you ,took really small time to complete the job.

worker.php:

echo "Starting\n";$gmworker = new GearmanWorker();# Add default server (localhost).$gmworker->addServer('127.0.0.1', '4730');$gmworker->addFunction("jsonValid", "jsonValid");print "Waiting for job...\n";while ($gmworker->work()) {    if ($gmworker->returnCode() != GEARMAN_SUCCESS) {        echo "return_code: " . $gmworker->returnCode() . "\n";        break;    }}function jsonValid($job){    return 'ToastyPHP!';}

Client.php

ini_set('memory_limit', '1G');$client = new GearmanClient();$client->addServer('127.0.0.1', '4730');$client->setCompleteCallback("complete");$time = time();echo "<pre>Sending job..." . "\n";$schema = file_get_contents('AllSets.json');$data = file_get_contents('AllSets.json');$gearmanData = Array(    'schema' => $schema,    'data' => $data);$gearmanDataString = json_encode($gearmanData, JSON_FORCE_OBJECT);$client->addTask("jsonValid", $gearmanDataString, null, 'Json');$client->runTasks();echo "Job finished\n";$endtime = time();print "Completed in " . ($endtime - $time) . ' seconds' . "\n";function complete($task){    print "Unique : " . $task->unique() . "\n";    print "Data : " . $task->data() . "\n";}

I have used the addTask and runTasks methods instead of doNormal.For the json data to be send I used the AllSets.json file from http://mtgjson.com/ around 30Mb size(total load), the job finised in 1 Sec , and after trying a file of around 200Mb it took 4 sec.