You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by andriy_heikal <an...@telkom.net> on 2007/11/19 06:11:29 UTC

ActiveMQ Sending Performance

Hi Guys,

I'm newbie on ActiveMQ. I've been trying to develop JMS using ActiveMQ. I
create 2 file
first as sender :
package tutorial.jms;

import java.util.Date;

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.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

public class HelloQueueSender {
    public static void main(String[] args) throws JMSException {
        ConnectionFactory factory = new ActiveMQConnectionFactory(
                ActiveMQConnection.DEFAULT_USER,
                ActiveMQConnection.DEFAULT_PASSWORD,
                ActiveMQConnection.DEFAULT_BROKER_URL);
        Date mulai = new Date();
        System.out.println("Start Sending : " + mulai);

        Connection conn = factory.createConnection();

        Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

        Queue destination = sess.createQueue("test");

        MessageProducer prod = sess.createProducer(destination);
        TextMessage msg = sess.createTextMessage();
        msg.setText("Hello JMS");

        
        int i = 1;
        while (i<=5000){
        	prod.send(msg);
        	i++;
        }

        prod.close();
        sess.close();
        conn.close();
        Date selesai = new Date();
        System.out.println("End Sending : " + selesai);
    }
}


second is for receiver :
package tutorial.jms;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

public class HelloQueueReceiver {
    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ActiveMQConnectionFactory(
                ActiveMQConnection.DEFAULT_USER,
                ActiveMQConnection.DEFAULT_PASSWORD,
                ActiveMQConnection.DEFAULT_BROKER_URL);

        Date mulai = new Date();
        System.out.println("Start Receiving : " + mulai);
        Connection conn = factory.createConnection();

        Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

        Queue destination = sess.createQueue("test");

        MessageConsumer consumer = sess.createConsumer(destination);
        conn.start();
        int counter = 1;
        while(true) {           
            Message msg = consumer.receive(1000);
            if (msg == null) break;
            if (msg instanceof TextMessage) {
                TextMessage txtmsg = (TextMessage) msg;
            }
        }

        consumer.close();
        sess.close();
        conn.close();
        Date selesai = new Date();
        System.out.println("End Receiving : " + selesai);
    }
} 
=======================================================
What my concern is sender performance, for 5000 messages takes 135sec or
37msg/sec but receiver performance is very good at 2500msg/sec. My question
is why it so be different, I guess my code is wrong.
Can anybody help me solved this problem?

Regards,

Heikal


-- 
View this message in context: http://www.nabble.com/ActiveMQ-Sending-Performance-tf4833383s2354.html#a13827979
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: ActiveMQ Sending Performance

Posted by andriy_heikal <an...@telkom.net>.
I've add setUseAsyncSend(true) to connection factory and the performance
boost to 2k-4k/sec using my notebook depend on CPU idle. ActiveMQ is very
robust. My problem resolved, many thanks for the help. 


James.Strachan wrote:
> 
> Also if you don't want to block until each message has been written to
> disk before sending the next one, you could use async sending which
> boosts performance a fair bit.
> 
> For more details see...
> http://open.iona.com/wiki/display/ProdInfo/FUSE+Message+Broker+Performance+Tuning+Guide
> 
> On 19/11/2007, Vinod Venkatraman <vi...@gmail.com> wrote:
>>
>> Ur sender code looks fine to me, are u sure ur messages are not being
>> persisted by ActiveMQ.
>> Persistence can slow down send considerably. Check ur ActiveMQ config
>> file
>> for persistence.
>>
>> http://activemq.apache.org/persistence.html
>>
>>
>>
>> andriy_heikal wrote:
>> >
>> > Hi Guys,
>> >
>> > I'm newbie on ActiveMQ. I've been trying to develop JMS using ActiveMQ.
>> I
>> > create 2 file
>> > first as sender :
>> > package tutorial.jms;
>> >
>> > import java.util.Date;
>> >
>> > 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.activemq.ActiveMQConnection;
>> > import org.apache.activemq.ActiveMQConnectionFactory;
>> >
>> > public class HelloQueueSender {
>> >     public static void main(String[] args) throws JMSException {
>> >         ConnectionFactory factory = new ActiveMQConnectionFactory(
>> >                 ActiveMQConnection.DEFAULT_USER,
>> >                 ActiveMQConnection.DEFAULT_PASSWORD,
>> >                 ActiveMQConnection.DEFAULT_BROKER_URL);
>> >         Date mulai = new Date();
>> >         System.out.println("Start Sending : " + mulai);
>> >
>> >         Connection conn = factory.createConnection();
>> >
>> >         Session sess = conn.createSession(false,
>> > Session.AUTO_ACKNOWLEDGE);
>> >
>> >         Queue destination = sess.createQueue("test");
>> >
>> >         MessageProducer prod = sess.createProducer(destination);
>> >         TextMessage msg = sess.createTextMessage();
>> >         msg.setText("Hello JMS");
>> >
>> >
>> >         int i = 1;
>> >         while (i<=5000){
>> >               prod.send(msg);
>> >               i++;
>> >         }
>> >
>> >         prod.close();
>> >         sess.close();
>> >         conn.close();
>> >         Date selesai = new Date();
>> >         System.out.println("End Sending : " + selesai);
>> >     }
>> > }
>> >
>> >
>> > second is for receiver :
>> > package tutorial.jms;
>> >
>> > import javax.jms.Connection;
>> > import javax.jms.ConnectionFactory;
>> > import javax.jms.JMSException;
>> > import javax.jms.Message;
>> > import javax.jms.MessageConsumer;
>> > import javax.jms.Queue;
>> > import javax.jms.Session;
>> > import javax.jms.TextMessage;
>> >
>> > import org.apache.activemq.ActiveMQConnection;
>> > import org.apache.activemq.ActiveMQConnectionFactory;
>> >
>> > public class HelloQueueReceiver {
>> >     public static void main(String[] args) throws Exception {
>> >         ConnectionFactory factory = new ActiveMQConnectionFactory(
>> >                 ActiveMQConnection.DEFAULT_USER,
>> >                 ActiveMQConnection.DEFAULT_PASSWORD,
>> >                 ActiveMQConnection.DEFAULT_BROKER_URL);
>> >
>> >         Date mulai = new Date();
>> >         System.out.println("Start Receiving : " + mulai);
>> >         Connection conn = factory.createConnection();
>> >
>> >         Session sess = conn.createSession(false,
>> > Session.AUTO_ACKNOWLEDGE);
>> >
>> >         Queue destination = sess.createQueue("test");
>> >
>> >         MessageConsumer consumer = sess.createConsumer(destination);
>> >         conn.start();
>> >         int counter = 1;
>> >         while(true) {
>> >             Message msg = consumer.receive(1000);
>> >             if (msg == null) break;
>> >             if (msg instanceof TextMessage) {
>> >                 TextMessage txtmsg = (TextMessage) msg;
>> >             }
>> >         }
>> >
>> >         consumer.close();
>> >         sess.close();
>> >         conn.close();
>> >         Date selesai = new Date();
>> >         System.out.println("End Receiving : " + selesai);
>> >     }
>> > }
>> > =======================================================
>> > What my concern is sender performance, for 5000 messages takes 135sec
>> or
>> > 37msg/sec but receiver performance is very good at 2500msg/sec. My
>> > question is why it so be different, I guess my code is wrong.
>> > Can anybody help me solved this problem?
>> >
>> > Regards,
>> >
>> > Heikal
>> >
>> >
>> >
>>
>> --
>>
>> View this message in context:
>> http://www.nabble.com/ActiveMQ-Sending-Performance-tf4833383s2354.html#a13830613
>>
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/ActiveMQ-Sending-Performance-tf4833383s2354.html#a13849072
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: ActiveMQ Sending Performance

Posted by James Strachan <ja...@gmail.com>.
Also if you don't want to block until each message has been written to
disk before sending the next one, you could use async sending which
boosts performance a fair bit.

For more details see...
http://open.iona.com/wiki/display/ProdInfo/FUSE+Message+Broker+Performance+Tuning+Guide

On 19/11/2007, Vinod Venkatraman <vi...@gmail.com> wrote:
>
> Ur sender code looks fine to me, are u sure ur messages are not being
> persisted by ActiveMQ.
> Persistence can slow down send considerably. Check ur ActiveMQ config file
> for persistence.
>
> http://activemq.apache.org/persistence.html
>
>
>
> andriy_heikal wrote:
> >
> > Hi Guys,
> >
> > I'm newbie on ActiveMQ. I've been trying to develop JMS using ActiveMQ. I
> > create 2 file
> > first as sender :
> > package tutorial.jms;
> >
> > import java.util.Date;
> >
> > 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.activemq.ActiveMQConnection;
> > import org.apache.activemq.ActiveMQConnectionFactory;
> >
> > public class HelloQueueSender {
> >     public static void main(String[] args) throws JMSException {
> >         ConnectionFactory factory = new ActiveMQConnectionFactory(
> >                 ActiveMQConnection.DEFAULT_USER,
> >                 ActiveMQConnection.DEFAULT_PASSWORD,
> >                 ActiveMQConnection.DEFAULT_BROKER_URL);
> >         Date mulai = new Date();
> >         System.out.println("Start Sending : " + mulai);
> >
> >         Connection conn = factory.createConnection();
> >
> >         Session sess = conn.createSession(false,
> > Session.AUTO_ACKNOWLEDGE);
> >
> >         Queue destination = sess.createQueue("test");
> >
> >         MessageProducer prod = sess.createProducer(destination);
> >         TextMessage msg = sess.createTextMessage();
> >         msg.setText("Hello JMS");
> >
> >
> >         int i = 1;
> >         while (i<=5000){
> >               prod.send(msg);
> >               i++;
> >         }
> >
> >         prod.close();
> >         sess.close();
> >         conn.close();
> >         Date selesai = new Date();
> >         System.out.println("End Sending : " + selesai);
> >     }
> > }
> >
> >
> > second is for receiver :
> > package tutorial.jms;
> >
> > import javax.jms.Connection;
> > import javax.jms.ConnectionFactory;
> > import javax.jms.JMSException;
> > import javax.jms.Message;
> > import javax.jms.MessageConsumer;
> > import javax.jms.Queue;
> > import javax.jms.Session;
> > import javax.jms.TextMessage;
> >
> > import org.apache.activemq.ActiveMQConnection;
> > import org.apache.activemq.ActiveMQConnectionFactory;
> >
> > public class HelloQueueReceiver {
> >     public static void main(String[] args) throws Exception {
> >         ConnectionFactory factory = new ActiveMQConnectionFactory(
> >                 ActiveMQConnection.DEFAULT_USER,
> >                 ActiveMQConnection.DEFAULT_PASSWORD,
> >                 ActiveMQConnection.DEFAULT_BROKER_URL);
> >
> >         Date mulai = new Date();
> >         System.out.println("Start Receiving : " + mulai);
> >         Connection conn = factory.createConnection();
> >
> >         Session sess = conn.createSession(false,
> > Session.AUTO_ACKNOWLEDGE);
> >
> >         Queue destination = sess.createQueue("test");
> >
> >         MessageConsumer consumer = sess.createConsumer(destination);
> >         conn.start();
> >         int counter = 1;
> >         while(true) {
> >             Message msg = consumer.receive(1000);
> >             if (msg == null) break;
> >             if (msg instanceof TextMessage) {
> >                 TextMessage txtmsg = (TextMessage) msg;
> >             }
> >         }
> >
> >         consumer.close();
> >         sess.close();
> >         conn.close();
> >         Date selesai = new Date();
> >         System.out.println("End Receiving : " + selesai);
> >     }
> > }
> > =======================================================
> > What my concern is sender performance, for 5000 messages takes 135sec or
> > 37msg/sec but receiver performance is very good at 2500msg/sec. My
> > question is why it so be different, I guess my code is wrong.
> > Can anybody help me solved this problem?
> >
> > Regards,
> >
> > Heikal
> >
> >
> >
>
> --
>
> View this message in context: http://www.nabble.com/ActiveMQ-Sending-Performance-tf4833383s2354.html#a13830613
>
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>


-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: ActiveMQ Sending Performance

Posted by Vinod Venkatraman <vi...@gmail.com>.
Ur sender code looks fine to me, are u sure ur messages are not being
persisted by ActiveMQ. 
Persistence can slow down send considerably. Check ur ActiveMQ config file
for persistence.

http://activemq.apache.org/persistence.html


andriy_heikal wrote:
> 
> Hi Guys,
> 
> I'm newbie on ActiveMQ. I've been trying to develop JMS using ActiveMQ. I
> create 2 file
> first as sender :
> package tutorial.jms;
> 
> import java.util.Date;
> 
> 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.activemq.ActiveMQConnection;
> import org.apache.activemq.ActiveMQConnectionFactory;
> 
> public class HelloQueueSender {
>     public static void main(String[] args) throws JMSException {
>         ConnectionFactory factory = new ActiveMQConnectionFactory(
>                 ActiveMQConnection.DEFAULT_USER,
>                 ActiveMQConnection.DEFAULT_PASSWORD,
>                 ActiveMQConnection.DEFAULT_BROKER_URL);
>         Date mulai = new Date();
>         System.out.println("Start Sending : " + mulai);
> 
>         Connection conn = factory.createConnection();
> 
>         Session sess = conn.createSession(false,
> Session.AUTO_ACKNOWLEDGE);
> 
>         Queue destination = sess.createQueue("test");
> 
>         MessageProducer prod = sess.createProducer(destination);
>         TextMessage msg = sess.createTextMessage();
>         msg.setText("Hello JMS");
> 
>         
>         int i = 1;
>         while (i<=5000){
>         	prod.send(msg);
>         	i++;
>         }
> 
>         prod.close();
>         sess.close();
>         conn.close();
>         Date selesai = new Date();
>         System.out.println("End Sending : " + selesai);
>     }
> }
> 
> 
> second is for receiver :
> package tutorial.jms;
> 
> import javax.jms.Connection;
> import javax.jms.ConnectionFactory;
> import javax.jms.JMSException;
> import javax.jms.Message;
> import javax.jms.MessageConsumer;
> import javax.jms.Queue;
> import javax.jms.Session;
> import javax.jms.TextMessage;
> 
> import org.apache.activemq.ActiveMQConnection;
> import org.apache.activemq.ActiveMQConnectionFactory;
> 
> public class HelloQueueReceiver {
>     public static void main(String[] args) throws Exception {
>         ConnectionFactory factory = new ActiveMQConnectionFactory(
>                 ActiveMQConnection.DEFAULT_USER,
>                 ActiveMQConnection.DEFAULT_PASSWORD,
>                 ActiveMQConnection.DEFAULT_BROKER_URL);
> 
>         Date mulai = new Date();
>         System.out.println("Start Receiving : " + mulai);
>         Connection conn = factory.createConnection();
> 
>         Session sess = conn.createSession(false,
> Session.AUTO_ACKNOWLEDGE);
> 
>         Queue destination = sess.createQueue("test");
> 
>         MessageConsumer consumer = sess.createConsumer(destination);
>         conn.start();
>         int counter = 1;
>         while(true) {           
>             Message msg = consumer.receive(1000);
>             if (msg == null) break;
>             if (msg instanceof TextMessage) {
>                 TextMessage txtmsg = (TextMessage) msg;
>             }
>         }
> 
>         consumer.close();
>         sess.close();
>         conn.close();
>         Date selesai = new Date();
>         System.out.println("End Receiving : " + selesai);
>     }
> } 
> =======================================================
> What my concern is sender performance, for 5000 messages takes 135sec or
> 37msg/sec but receiver performance is very good at 2500msg/sec. My
> question is why it so be different, I guess my code is wrong.
> Can anybody help me solved this problem?
> 
> Regards,
> 
> Heikal
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/ActiveMQ-Sending-Performance-tf4833383s2354.html#a13830613
Sent from the ActiveMQ - User mailing list archive at Nabble.com.