We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Beanstalk Queue performance

I'm receiving strange numbers from my test...can anyone confirm? Is there an error somewhere? I use the following code:


<?php
// Composer
//{
//  "require": {
//      "pda/pheanstalk": "~3.0"
//  }
//}

require_once __DIR__ . '/vendor/autoload.php';

/**
 * This file belongs to streepoly.com
 * Created by Dominik Piekarski
 */

//Connect to the queue
$queue = new Phalcon\Queue\Beanstalk(array(
    'host' => '127.0.0.1'
));
$queue->choose('default');
$targetTime = time() + 60;
$stime = microtime(TRUE);
for ($i = 0; $i < 1000; $i++) {
    $dtSerialized = serialize(new \DateTime('+'.mt_rand(1, 22).' hour +'.mt_rand(1, 59).' minutes + '.mt_rand(1, 59).' seconds'));
    $queue->put(array('userTask' => 123456789, 'body' => $dtSerialized),
        array('priority' => 999, 'delay' => ($targetTime-time()), 'ttr' => 3600)
    );

}
var_dump('PhalconQueue:' . $i . ' -- ' . (microtime(TRUE) - $stime));

use Pheanstalk\Pheanstalk;

$pheanstalk = new Pheanstalk('127.0.0.1');
$stime = microtime(TRUE);
for ($i = 0; $i <= 1000; $i++) {
    $dtSerialized = serialize(new \DateTime('+'.mt_rand(1, 22).' hour +'.mt_rand(1, 59).' minutes + '.mt_rand(1, 59).' seconds'));
    $res = $pheanstalk->put(serialize(array('userTask' => 123456789, 'body' => $dtSerialized)),
        999, mt_rand(0, 300), 3600
    );
}
var_dump('PheanstalkQueue:' . $i . ' -- ' . (microtime(TRUE) - $stime));

Output is:

$ php5 -f beanstalk-producer.php
string(36) "PhalconQueue:1000 -- 40.334742069244"
string(40) "PheanstalkQueue:1001 -- 0.22178196907043"


51.1k

I can confirm with:

string(36) "PhalconQueue:1000 -- 40.201565027237"
string(38) "PheanstalkQueue:1001 -- 0.329185962677"
  • I use a vagrant machine