Rabbitmq 3.5.1 slow publish rate

899 views Asked by At

I've setup rabbitmq with default config both on my pc and server and noticed a strange behavior on rabbitmq publish rate, no matter how fast i publish messages to rabbitmq the publish rate stays at 12/s both on my pc and the server while these two systems are quite different on the amount of ram and cpu!

For testing purpose i've written a super simple code that published messages to a queue on rabbitmq and again i can see the 12/s publish rate!

i think this is ridiculously low and the publish rate must be way much higher.

I've tested both durable and transient exchanges and messages but the result was the same.

How can i increase the publish rate?

Here is the code:

<?php
    for($i=1;$i<20000;$i++){
    $connection = new AMQPConnection('localhost', 5672, 'guest', 'guest');
        $channel = $connection->channel();
        $channel->exchange_declare('test', 'direct', false, false, false);
        $msg = new AMQPMessage('test '.$i);
        $channel->basic_publish($msg, 'test');
        $channel->close();
        $connection->close();
    }

?>

1

There are 1 answers

0
Nicolas Labrot On BEST ANSWER

Avoids creating connection, channel and exchange per iteration. Instead creates them before the iteration and closes them after the loop.

They are costly operations (especially connection and channel). connection and channel should be created and reused.

$connection = new AMQPConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
$channel->exchange_declare('test', 'direct', false, false, false);

for($i=1;$i<20000;$i++){
    $msg = new AMQPMessage('test '.$i);
    $channel->basic_publish($msg, 'test');
}
$channel->close();
$connection->close();