activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andriy_heikal <andriy_hei...@telkom.net>
Subject ActiveMQ Sending Performance
Date Mon, 19 Nov 2007 05:11:29 GMT

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.


Mime
View raw message