3 Replies Latest reply on Aug 21, 2013 4:54 AM by Andy Taylor

    How to perform load test of standalone hornetQ

    Arjun A Newbie

      Hi all,

       

      I have configured standalone hornetQ with 3 queues.

      I am using JBOSS AS 7.1.1 Final with 2 applications.

      1) producer.war- when a rest service is called , it will insert one  TextMessage into 3 queues.

      Here is the code for producer:

       

      package com.hornetq.producer.service.impl;
      
      import javax.annotation.Resource;
      import javax.enterprise.context.ApplicationScoped;
      import javax.jms.Connection;
      import javax.jms.ConnectionFactory;
      import javax.jms.JMSException;
      import javax.jms.MessageProducer;
      import javax.jms.Queue;
      import javax.jms.Session;
      import javax.jms.TextMessage;
      
      import org.apache.log4j.Logger;
      
      import com.hornetq.producer.service.QueueProducerTest;
      
      @ApplicationScoped
      public class QueueProducerTestImpl implements QueueProducerTest {
      
          private static final Logger logger = Logger.getLogger(QueueProducerTestImpl.class);
      
          @Resource(mappedName = "java:/MyConnection")
          private ConnectionFactory connectionFactory;
          @Resource(mappedName = "/queue/testQueue1")
          private Queue queue1;
      
          @Resource(mappedName = "/queue/testQueue2")
          private Queue queue2;
          @Resource(mappedName = "/queue/testQueue3")
          private Queue queue3;
      
      
      
          @Override
          public void sendMessage() {
      
              Connection connection = null;
              Session session = null;
              MessageProducer publisher1 = null;
              MessageProducer publisher2 = null;
              MessageProducer publisher3 = null;
              try {
      
                  connection = this.connectionFactory.createConnection();
                  session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                  publisher1 = session.createProducer(this.queue1);
                  publisher2 = session.createProducer(this.queue2);
                  publisher3 = session.createProducer(this.queue3);
                  connection.start();
      
      
      
                  TextMessage textMessage = session.createTextMessage("hello world");
      
      
                  publisher1.send(textMessage);
      
      
                  publisher2.send(textMessage);
      
      
                  publisher3.send(textMessage);
      
      
      
              } catch (JMSException jmse) {
      
                  logger.error("sendMessage JMSException " + jmse.getMessage(), jmse);
      
      
      
              } finally {
      
                  try {
                      if (publisher1 != null) {
                          publisher1.close();
                      }
                      if (publisher2 != null) {
                          publisher2.close();
                      }
                      if (publisher3 != null) {
                          publisher3.close();
                      }
                      if (session != null) {
                          session.close();
                      }
                      if (connection != null) {
                          connection.close();
                      }
                  } catch (JMSException jmse) {
                      logger.error("sendMessage JMSException finally " + jmse.getMessage(), jmse);
      
                  }
              }
          }
      }
      

       

      2) i have consumer.war which has 3 MDBs which will listen to 3 queues.

      Here is the code of one consumer, other 2 are same except different queues:

       

      package com.hornetq.consumer.service.impl;
      
      import javax.ejb.ActivationConfigProperty;
      import javax.ejb.MessageDriven;
      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.TextMessage;
      
      import org.jboss.ejb3.annotation.ResourceAdapter;
      import org.slf4j.Logger;
      import org.slf4j.LoggerFactory;
      
      
      
      @MessageDriven(activationConfig = {
              @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
              @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/testQueue1"),
              @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "200"),
              @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
      @ResourceAdapter("MyConnection")
      public class MessageConsumerQueue1Test extends BaseQueueConsumer {
      
          private static final Logger logger = LoggerFactory.getLogger(MessageConsumerQueue1Test.class);
      
      
      
          @Override
          public void onMessage(Message message) {
      
      
      
              if (message instanceof TextMessage) {
                  try {
                      String textMessage = ((TextMessage) message).getText();
                      logger.info("textMessage:" + textMessage);
                  } catch (JMSException e) {
      
                      logger.error("JMSException # 1 # Not a valid message for this Queue MDB" + e.getMessage());
      
                  }
      
              } else {
                  logger.error(" # 1 # Not a valid message for this Queue MDB");
              }
      
          }
      
      
      }
      

      I want to do a load test on the hornetQ , by sending 200 messages in one second.

      I am using Jmeter, I configured jmeter by 20 threads and ramp up time as 1 and loop count as 10, which inserted 200 messages in approx. 8 seconds.

      how can achieve the load test to send 200 messages in 1 seconds. Is hardware configuration of my machine will also depend?

      I am attaching my jboss stanalone configuration xml file,hornetq-configuration.xml and hornetq-jms.xml

       

      My system configuration:

      OS - windows 7 32-bit

      processor- pentium dual core CPU- E5400 , 2.7 GHz

      RAM - 3 GB

       

      please help.

       

      Thanks in advance.