MDB queue consumption issue
sash101 Feb 4, 2016 4:24 AMI have a MDB queue consumption issues in regards to consumption speed, and also an issues with number of active MDB instances that service the queue on both WildFly 8.1. and 9.0.2.
The consumption issues is that it takes around 25ms for a MDB to consume a new message from a jms queue. To demonstrate I've made a simple Servlet that sends 100 messages to a queue, and on the other side a simple MDB that consumes those messages. MDB simulates processing of some data with Thread.sleep(50) and moves on to the next message. To configure wildfly I've used standalone-full-ha.xml and added a queue/test. The code:
Servlets doGet:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String destinationName = "java:/jms/queue/test"; PrintWriter out = response.getWriter(); Context ic = null; ConnectionFactory cf = null; Connection connection = null; try { ic = new InitialContext(); cf = (ConnectionFactory)ic.lookup("/ConnectionFactory"); Queue queue = (Queue)ic.lookup(destinationName); connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer publisher = session.createProducer(queue); connection.start(); for (int i = 0; i < 100; i++){ TextMessage message = session.createTextMessage("Hello " + i); publisher.send(message); LOGGER.info("Sent msg " + i); } out.println("Message sento to the JMS Provider"); } catch (Exception exc) { exc.printStackTrace(); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e) { e.printStackTrace(); } } } }
MDB:
@MessageDriven( activationConfig = { @ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/queue/test"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1") }, name = "ConsumerMdb") public class ConsumerMdb implements MessageListener { private static final Logger LOGGER = Logger.getLogger(ConsumerMdb.class.getName()); /** * Default constructor. */ private static int globalId = 1; private int id; public ConsumerMdb() { id = ++globalId; LOGGER.warning("created mdb " + id); } /** * @see MessageListener#onMessage(Message) */ public void onMessage(Message message) { LOGGER.info("IN ON MSG " + id); try { Thread.sleep(50); TextMessage msg = (TextMessage) message; LOGGER.info("Proccessing: " + msg.getText()); } catch (Exception e) { e.printStackTrace(); } LOGGER.info("OUT ON MSG"); } }
I've tested this on 2 PCs running on Windows and on CentOS as VirtualMachine they all have time difference of around 25ms between "OUT ON MSG" log and "IN ON MSG" log. I've tested the same code on Apache TomEE, and the consumtion speed on it is around 1ms. I've checked everything I could think off and I couldn't find the reason causing it. Any ideas how to fix this issue?
Another issue I have with wildfly is the number of active MDB instances servicing a single queue. Eg. When I remove maxSession property the number of active MDBs is around 2-3 on Windows while on CentOS is around 9. I've tried ussing pool annotation min and max session properties with no avail. When I increase the pool size to eg. 4000 wildfly will initially create 4000 MDBs and when servlet starts sending messages it'll create 2 new MDBs and just use them. Any ideas how to fix this also?