Php-amqplib: Have you ever did a performance test for php-amqplib?

Created on 6 May 2016  Â·  4Comments  Â·  Source: php-amqplib/php-amqplib

Today I did a benchmark to test the write performance of RabbitMQ with 2 clients written in PHP and C.

The PHP client using php-amqplib, The C client is from this github project https://github.com/liuhaobupt/rabbitmq-benchmark

RabbitMQ installed on a box with Intel Xeon 2.6G 24 cores, 192G memory.

Here is the statistics:

The C client produce 10K messages with 128 bytes long in just 47ms.
The PHP client produce the same messages in nearly 400s.

Which means that the C client is almost 10 thousands faster then php when producing RabbitMQ message.

I know it's unfair to compare php with c in performance. But the benchmark is so impressive. And that's why I want to share this with you guys.

Most helpful comment

@ant-hill @videlalvaro

Thanks for your reply.

I checked the PHP benchmark source. And I found that every time before I publish a message, there is a exchange_declare call, which is not necessary in a benchmark. After I remove this function call, I got a performance boost: 17K messages per second!

Now, the consumer's performance is far behind producer's, which is 3.5K per second. increase the prefetch count from 1 to 5 to 10 and then to 20, nothings has changed, still 3.5K per second.

Here is the consumer benchmark code:

<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;

$connection = new AMQPStreamConnection('localhost', 5672, '*****', '*****', '*****');
$channel = $connection->channel();

$i = 0;
$callback = function($msg){
  global $i;

  $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
  if ($i++ > 10000) {
    echo microtime(true), PHP_EOL;
    exit;
  }
};

$channel->basic_qos(null, 5, null);
$channel->basic_consume('the-test-queue', '', false, false, false, false, $callback);

echo microtime(true), PHP_EOL;

while(count($channel->callbacks)) {
    $channel->wait();
}

$channel->close();
$connection->close();

All 4 comments

@zengkun100 Can you share benchmark?

Definitely share your benchmark. The PHP library was able to do 10k msgs in
less than a second.

You are basically saying that php-amqplib can only send 25msgs/sec which is
far from true.
On Fri, May 6, 2016 at 1:13 PM Ivan [email protected] wrote:

@zengkun100 https://github.com/zengkun100 Can you share you benchmark?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
https://github.com/php-amqplib/php-amqplib/issues/397#issuecomment-217413450

@ant-hill @videlalvaro

Thanks for your reply.

I checked the PHP benchmark source. And I found that every time before I publish a message, there is a exchange_declare call, which is not necessary in a benchmark. After I remove this function call, I got a performance boost: 17K messages per second!

Now, the consumer's performance is far behind producer's, which is 3.5K per second. increase the prefetch count from 1 to 5 to 10 and then to 20, nothings has changed, still 3.5K per second.

Here is the consumer benchmark code:

<?php
require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;

$connection = new AMQPStreamConnection('localhost', 5672, '*****', '*****', '*****');
$channel = $connection->channel();

$i = 0;
$callback = function($msg){
  global $i;

  $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
  if ($i++ > 10000) {
    echo microtime(true), PHP_EOL;
    exit;
  }
};

$channel->basic_qos(null, 5, null);
$channel->basic_consume('the-test-queue', '', false, false, false, false, $callback);

echo microtime(true), PHP_EOL;

while(count($channel->callbacks)) {
    $channel->wait();
}

$channel->close();
$connection->close();

I am closing this due to inactivity and lack of a complete set of producer / consumer code.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tugrul picture tugrul  Â·  3Comments

helloEson picture helloEson  Â·  3Comments

prolic picture prolic  Â·  6Comments

MaxwellZY picture MaxwellZY  Â·  5Comments

ltanme picture ltanme  Â·  8Comments