2
votes

I am experimenting with a PooledConnectionFactory in ActiveMQ (5.12.1) - but I don't see any performance gain (even worse: using PooledConnectionFactory is slower than ActiveMQConnectionFactory).

What I do: Sending a few 100.000 messages in several threads (using CompletableFuture). One run with a ActiveMQConnectionFactory, the other with PooledConnectionFactory:

1st Run:

ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection connection = cf.createConnection();
connection.start();a
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(null);
final Topic topic = session.createTopic(topicName);
final ObjectMessage message = session.createObjectMessage(myObject);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
producer.send(topic, message);

2nd Run:

PooledConnectionFactory pcf = new PooledConnectionFactory("tcp://localhost:61616");
pcf.setMaxConnections(8);
Connection connection = pcf.createConnection();
connection.start();
...

More details:

  • My test application creates 250 MessageProducers, each one running in its own thread.

  • Connection/Session/MessageProducer are only created once - and never closed.

  • Messages are sent in a loop per thread, as fast as possible.

I don't see why a PooledConnectionFactory (connections > 1) does not result in an increased number of messages/second - compared to a non-PooledConnectionFactory (connections == 1).

Am I setting up the PooledConnectionFactory the wrong way? Am I missing something?

1
What performance are you talking about , can you please be more specific - Sundar
The answer here would be the same as the one you got in the ActiveMQ users mailing list which is to provide more information given that the scope of your question is to vague. - Tim Bish

1 Answers

0
votes

You are using PooledConnectionFactory for the wrong scenario.

Note that according to JMS spec, you should use a single Session in multiple threads.

Typically, JMS client frameworks use code similar to:

  1. create connection
  2. create session
  3. create producer
  4. send message
  5. close producer
  6. close session
  7. close connection

That is the safe way to do JMS, but it costs a lot in setting up and tearing down connections. The PooledConnectionFactory will instead keep a pool of connected connections and lease them to thread while sending.

If you try sending 10k msgs and reconnect for each message, you will notice a great performance increase with a pooled factory.

Some background: http://activemq.apache.org/jmstemplate-gotchas.html