MessageListener speed when connecting to local messaging com
davidrh Jun 21, 2006 3:02 AMI've noticed that dequeuing messages when connecting to a JBoss messaging server on localhost is heaps faster than when you connect to a remote server. Naturally, I would expect the local server to be faster, but connecting to a remote server I am only getting 2 - 3 messages per second using a MessageListener that does nothing. I've also noticed the same behaviour when browsing queues with Hermes - locally you get 100's of message/second and remotely it's only 2 - 3 messages per second.
A rough test to see this is shown below. Am I doing anything wrong in the way I am using MessageListeners? I can get more throughput by increasing the number of sessions and message listeners I create, but I just wanted to know if there is anything else I can do to make it faster. The browsing in Hermes is a bit of a problem, as its slow enough to be unusable with anything more than a few messages.
I am using JBoss Message 1.0.1 CR2 installed on JBoss 4.0.4 GA using the standalone installer provided.
David
public class TestMultiSessionMessageListener {
/**
* @param args
*/
public static void main(String[] args) {
TestMultiSessionMessageListener ml = new TestMultiSessionMessageListener();
try {
ml.test();
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void test() throws JMSException {
Hashtable properties = new Hashtable();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
properties.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
properties.put(Context.PROVIDER_URL, "jnp://D102334:1099");
properties.put(Context.SECURITY_PRINCIPAL, "admin");
properties.put(Context.SECURITY_CREDENTIALS, "admin");
ConnectionFactory connectionFactory = null;
try {
Context context = new InitialContext(properties);
connectionFactory = (ConnectionFactory) context
.lookup("ConnectionFactory");
} catch (NamingException ne) {
throw new RuntimeException(ne);
}
Connection connection = connectionFactory.createConnection();
connection.start();
int numberOfProcesses = 1;
MessageConsumer[] consumers = new MessageConsumer[numberOfProcesses];
Session[] sessions = new Session[numberOfProcesses];
for (int i = 0; i < consumers.length; i++) {
sessions = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue q = sessions.createQueue("core.track");
consumers = sessions.createConsumer(q);
MessageListener ml = new MessageListener() {
public void onMessage(Message arg0) {
System.out.println(Thread.currentThread().getName());
}
};
consumers.setMessageListener(ml);
}
try {
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
}
}
}