Created
March 7, 2016 12:42
batch publishing benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'vendor/autoload.php'; | |
$amqpLibConnection = new \PhpAmqpLib\Connection\AMQPStreamConnection( | |
'localhost', | |
5672, | |
'guest', | |
'guest', | |
'/humus-amqp-test' | |
); | |
$amqpLibChannel = new \PhpAmqpLib\Channel\AMQPChannel($amqpLibConnection); | |
$extAmqpConnection = new \AMQPConnection(); | |
$extAmqpConnection->setHost('localhost'); | |
$extAmqpConnection->setPort(5672); | |
$extAmqpConnection->setLogin('guest'); | |
$extAmqpConnection->setPassword('guest'); | |
$extAmqpConnection->setVhost('/humus-amqp-test'); | |
$extAmqpConnection->connect(); | |
$extAmqpChannel = new \AMQPChannel($extAmqpConnection); | |
$extAmqpExchange = new \AMQPExchange($extAmqpChannel); | |
$extAmqpExchange->setName('test'); | |
$extAmqpExchange->setType('direct'); | |
$extAmqpExchange->declareExchange(); | |
// 1: amqp lib without batch | |
$start1 = microtime(1); | |
for ($i = 0; $i < 10; $i++) { | |
for ($j = 0; $j < 10000; $j++) { | |
$amqpLibChannel->basic_publish(new \PhpAmqpLib\Message\AMQPMessage('foo')); | |
} | |
} | |
$end1 = microtime(1) - $start1; | |
// 2: amqp lib with batch | |
$start2 = microtime(1); | |
for ($i = 0; $i < 10; $i++) { | |
for ($j = 0; $j < 10000; $j++) { | |
$amqpLibChannel->batch_basic_publish(new \PhpAmqpLib\Message\AMQPMessage('foo')); | |
} | |
$amqpLibChannel->publish_batch(); | |
} | |
$end2 = microtime(1) - $start2; | |
// 1: ext-amqp without batch | |
$start3 = microtime(1); | |
for ($i = 0; $i < 10; $i++) { | |
for ($j = 0; $j < 10000; $j++) { | |
$extAmqpExchange->publish('foo'); | |
} | |
} | |
$end3 = microtime(1) - $start3; | |
$extAmqpExchange->delete(); | |
echo 'RESULTS' . PHP_EOL; | |
echo 'php amqp lib without batch: ' . $end1 . PHP_EOL; | |
echo 'php amqp lib with batch: ' . $end2 . PHP_EOL; | |
echo 'ext-amqp without batch: ' . $end3 . PHP_EOL; | |
//RESULTS | |
//php amqp lib without batch: 1.8219351768494 | |
//php amqp lib with batch: 1.1404459476471 | |
//ext-amqp without batch: 0.25326800346375 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment