title: Redis / RabbitMQ - Pub / Sub - Performances
body: <p>I wrote a little test for a simple scenario:</p>
  
  <p>One publisher and one subscriber</p>
  
  <p>Publisher send 1000000 messages</p>
  
  <p>Subscriber receive the 1000000 messages</p>
  
  <p>First test with RabbitMQ, fanout Exchange, RabbitMq node type Ram : 320 seconds</p>
  
  <p>Second test with Redis, basic pub/Sub : 24 seconds</p>
  
  <p>Am i missing something? Why a such difference ? Is this a configuration problem or something?</p>
  
  <p>First scenario: one node.js process for the subscriber, one for the publisher, each one, one connection to rabbitmq with amqp node module.
  Second scénario: one node.js process for the subscriber, one for the publisher, each one got one connection to redis.</p>
  
  <p>Any help is welcom to understand... I can share the code if needed.</p>
  
  <p>i'm pretty new to all of this.
  What i need, is a high performances pub / sub messaging system. I'd like to have clustering capabilities.</p>
  
  <p>To run my test, i just launch the rabbitMq server (default configuration) and i use the following </p>
  
  <p>Publisher.js</p>
  
  <pre><code>var sys  = require('sys');
  var amqp = require('amqp');
  var nb_messages = process.argv[2];
  var connection  = amqp.createConnection({url: 'amqp://guest:guest@localhost:5672'});
  
  connection.addListener('ready', function () {
      exchangeName = 'myexchange';   
      var start = end = null;
      var exchange = connection.exchange(exchangeName, {type: 'fanout'}, function(exchange){
          start = (new Date()).getTime();
  
          for(i=1; i &lt;= nb_messages; i++){
              if (i%1000 == 0){
                  console.log("x");
              }
              exchange.publish("", "hello");
          }
  
          end = (new Date()).getTime();
          console.log("Publishing duration: "+((end-start)/1000)+" sec");
          process.exit(0);
      });
  });
  </code></pre>
  
  <p>Subscriber.js</p>
  
  <pre><code>var sys  = require('sys');
  var amqp = require('amqp');
  var nb_messages = process.argv[2];
  var connection = amqp.createConnection({url: 'amqp://guest:guest@localhost:5672'});
  
  connection.addListener('ready', function () {    
      exchangeName = 'myexchange';
      queueName    = 'myqueue'+Math.random();
  
      var queue    = connection.queue(queueName, function (queue) {
          queue.bind(exchangeName, "");
          queue.start       = false;
          queue.nb_messages = 0;
  
          queue.subscribe(function (message) {
              if (!queue.start){
                  queue.start = (new Date()).getTime();
              }
              queue.nb_messages++;
              if (queue.nb_messages % 1000 == 0){
                  console.log('+');
              }
              if (queue.nb_messages &gt;= nb_messages){
                  queue.end = (new Date()).getTime();
                  console.log("Ending at "+queue.end);
                  console.log("Receive duration: "+((queue.end - queue.start)/1000));
                  process.exit(0);
              }
          });
      });
  });
  </code></pre>