activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Gmeiner <>
Subject Slow performance of NMS api compared to Java
Date Tue, 26 Aug 2008 09:18:29 GMT
We are evaluating the NMS-API to connect a C# app to our ActiveMQ 
broker. For this we wrote a simple client which sends a request and 
waits for a reply (Client --> Broker --> Server --> Broker --> Client). 
The client/server C#-app runs in a single process with two different 
connections to the broker which resides on a different pc on the network.

This scenario takes about 200ms for each message transfered by the 
C#-API and less than 20ms by the Java-API although both do the same thing.

Does anybody have an idea what is going wrong or why there is such a big 
time differences?

Thank you for helping

Code for the C# test app follows:
using System;
using Apache.NMS;

namespace Test
	class SimpleTest
		private static readonly String URI = "tcp://broker:61616";
		private static readonly String REQUEST_QUEUE = "test.request";

		private static DateTime startOffset;

		public static void Main()
			IConnectionFactory factory = new NMSConnectionFactory(URI);

			Console.WriteLine("Press any key to quit.");

		private static void SetUpReceiver(IConnectionFactory factory)
			// set up receiver
			IConnection rConnection = factory.CreateConnection();
			ISession rSession = rConnection.CreateSession();
			IMessageConsumer rConsumer = 
			IMessageProducer rProducer = rSession.CreateProducer();
			rConsumer.Listener += delegate(IMessage message)
				OnMessage(rSession, rProducer, message);

		private static void SetUpSender(IConnectionFactory factory)
			IConnection sConnection = factory.CreateConnection();
			ISession sSession = sConnection.CreateSession();
			IMessageProducer sProducer = 
			IDestination replyDestination = sSession.CreateTemporaryQueue();
			IMessageConsumer sConsumer = sSession.CreateConsumer(replyDestination);

			for (int i = 0; i < 5; i++)
				Console.WriteLine("Test " + i);

				// send message and wait for reply
				IMessage requestMsg = sSession.CreateTextMessage("Request" + i);
				requestMsg.NMSReplyTo = replyDestination;

				startOffset = DateTime.Now;

				sProducer.Send(requestMsg, false, NMSConstants.defaultPriority, 

				WriteTimedMessage("Request message sent");

				IMessage replyMsg = sConsumer.Receive();

				WriteTimedMessage("Reply message received");

		private static void OnMessage(ISession session, IMessageProducer 
producer, IMessage message)
			WriteTimedMessage("Request message received");

			IMessage replyMsg = session.CreateTextMessage("Reply");
			producer.Send(message.NMSReplyTo, replyMsg, false, 
NMSConstants.defaultPriority, NMSConstants.defaultTimeToLive);

			WriteTimedMessage("Reply message sent");

		private static void WriteTimedMessage(String message)
			lock (typeof(SimpleTest))
				TimeSpan diff = DateTime.Now - startOffset;
				Console.WriteLine("{0} ms: {1}", diff.TotalMilliseconds, message);

View raw message