activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick <2to32min...@gmail.com>
Subject AMQ Beginner - slow producer
Date Thu, 14 Sep 2006 03:11:24 GMT

public class ActiveMqTest {
	
	public ActiveMqTest() {
	}
	///////////////////////////////////////////////////////
	// Just getting started with ActiveMQ.
	// I must be doing something very wrong to be getting such poor performance
on local sends (21 messages/sec).
	// Please take a quick look and see if there is something obvious.
	// This code is a derivative of HelloWorldProducer at
http://www.activemq.org/site/hello-world.html.
        // Thank you in advance for any help!
	///////////////////////////////////////////////////////
	// ActiveMQ version: ActiveMQ 4.0-M4 (per activemq --version)
	// OS, HW: Windows 2000 SP4; 900Mhz Pentium Dell Inspiron 8000 laptop,
512MB RAM
	// Broker started on local machine
	// Broker output follows:
	//
	// C:\activemq>bin\activemq
	// ACTIVEMQ_HOME: C:\activemq
	// Loading message broker from: xbean:activemq.xml
	// INFO  BrokerService                  - ActiveMQ 4.0-M4 JMS Message
Broker (localhost) is starting
	// INFO  BrokerService                  - For help or more information
please see: http://www.logicblaze.com
	// INFO  JDBCPersistenceAdapter         - Database driver recognized:
[apache_derby_embedded_jdbc_driver]
	// INFO  JournalPersistenceAdapter      - Journal Recovery Started from:
Active Journal: using 5 x 20.0 Megs at: ..\activemq-data\journal
	// INFO  JournalPersistenceAdapter      - Journal Recovered: 1 message(s)
in transactions recovered.
	// INFO  TransportServerThreadSupport   - Listening for connections at:
tcp://richlaptop:61616
	// INFO  TransportConnector             - Accepting connection on:
tcp://richlaptop:61616
	// WARN  MulticastDiscoveryAgent        - brokerName not set
	// INFO  TransportServerThreadSupport   - Listening for connections at:
tcp://richlaptop:61617?wireFormat=stomp
	// INFO  TransportConnector             - Accepting connection on:
tcp://richlaptop:61617?wireFormat=stomp
	// INFO  BrokerService                  - ActiveMQ JMS Message Broker
(localhost) started
	// INFO  NetworkConnector               - Establishing network connection
between vm://localhost?network=true and null at
failover:tcp://richlaptop:6161
	// INFO  VMTransportFactory             - binding to broker: localhost
	// INFO  TransportConnector             - Accepting connection on:
vm://localhost
	// INFO  ManagementContext              - JMX consoles can connect to
service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
	// INFO  DemandForwardingBridge         - Starting a network connection
between vm://localhost#0 and unconnected has been established.
	// INFO  DemandForwardingBridge         - Disconnecting loop back
connection.
	// INFO  VMTransportFactory             - Shutting down VM connectors for
broker: localhost
	// INFO  VMTransportFactory             - Shutting down VM connectors for
broker: localhost	//
	//
	// C:\activemq\bin>java -version
	// java version "1.5.0_02"
	// Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
	// Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)
	//
	// Method output:
	// Sending 200 messages
	// Sent 200 messages at a rate of 21.13494663425975 messages per second
	// ------------------ NOTES ------------------
	// If setDeliveryMode to NON_PERSISTENT rate jumps to 995 per second
	// All config files unchanged from installation and all log/data files
under install dir several months old.
	///////////////////////////////////////////////////////
	public static void main( String [] args ) {
		javax.jms.Connection connection = null;
		javax.jms.Session session = null;
		try {
			// Setup
			org.apache.activemq.ActiveMQConnectionFactory connectionFactory = new
org.apache.activemq.ActiveMQConnectionFactory( "tcp://localhost:61616" );
			connection = connectionFactory.createConnection();
			session = connection.createSession( false,
javax.jms.Session.AUTO_ACKNOWLEDGE );
			javax.jms.Destination destination = session.createQueue( "TestQueue" );
			javax.jms.MessageProducer producer = session.createProducer( destination
);
			producer.setDeliveryMode( javax.jms.DeliveryMode.PERSISTENT );
			connection.start();
			// Build and send message numToSend times
			int numToSend = 200;
			javax.jms.TextMessage message = session.createTextMessage();
			System.out.println( "Sending " + numToSend + " messages" );
System.out.flush();
			long t1 = System.currentTimeMillis();
			for ( int i = 0; i < numToSend; ++i ) {
				message.setText( "Message#" + Integer.toString( i ) );
				producer.send( message );
			}
			long t2 = System.currentTimeMillis();
			// Compute and print out send rate
			double rate = ( double ) numToSend/( (  double ) ( t2 - t1 )/1000.0 );
			System.out.println( "Sent " + numToSend + " messages at a rate of " +
rate + " messages per second" ); System.out.flush();
		}
		catch ( Exception eOuter ) {
			eOuter.printStackTrace();
		}
		finally {
			// Clean up
			try {
				if ( session != null ) session.close();
				if ( connection != null ) connection.close();
			}
			catch ( Exception eInner ) {
				eInner.printStackTrace();
			}
		}
	}
	
}

-- 
View this message in context: http://www.nabble.com/AMQ-Beginner---slow-producer-tf2269364.html#a6298777
Sent from the ActiveMQ - User forum at Nabble.com.


Mime
View raw message