How to optimize activemq

I use ActiveMQ to simulate server congestion in Java. And basically it's fine, but when I get more than 600 requests, the thing just goes WTF!

I think the bottleneck is my main server, which this guy is. I am already reusing the connection and creating various sessions to consume messages from clients. As I said, I use about 50-70 sessions per connection, reuse the connection and the queue. Any idea that I can reuse / optimize my components / listener below?

The architecture is as follows:

* = various

Client ---> JMS MasterQueue ---> * Master ---> JMS SlavaQueue ---> * SlaveQueue

Basically I create a Temp queue for each Master → Slave communication session, is this a big performance issue?

/**
 * This subclass implements the processing log of the Master JMS Server to
 * propagate the message to the Server (Slave) JMS queue.
 *
 * @author Marcos Paulino Roriz Junior
 *
 */
public class ReceiveRequests implements MessageListener {
    public void onMessage(Message msg) {
        try {
            ObjectMessage objMsg = (ObjectMessage) msg;

            // Saves the destination where the master should answer
            Destination originReplyDestination = objMsg.getJMSReplyTo();

            // Creates session and a sender to the slaves
            BankQueue slaveQueue = getSlaveQueue();
            QueueSession session = slaveQueue.getQueueConnection()
                    .createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            QueueSender sender = session
                    .createSender(slaveQueue.getQueue());

            // Creates a tempQueue for the slave tunnel the message to this
            // master and also create a masterConsumer for this tempQueue.
            TemporaryQueue tempDest = session.createTemporaryQueue();
            MessageConsumer masterConsumer = session
                    .createConsumer(tempDest);

            // Setting JMS Reply Destination to our tempQueue
            msg.setJMSReplyTo(tempDest);

            // Sending and waiting for answer
            sender.send(msg);
            Message msgReturned = masterConsumer.receive(getTimeout());

            // Let check if the timeout expired
            while (msgReturned == null) {
                sender.send(msg);
                msgReturned = masterConsumer.receive(getTimeout());
            }

            // Sends answer to the client
            MessageProducer producerToClient = session
                    .createProducer(originReplyDestination);
            producerToClient.send(originReplyDestination, msgReturned);
        } catch (JMSException e) {
            logger.error("NO REPLY DESTINATION PROVIDED", e);
        }
    }
}
+3
source share
2 answers

Well, after some reading, I learned how to optimize.

We need to reuse some session variables, such as sender and tempqueue. Instead of creating new ones.

Another approach is that the stack size for the thread in Java is lower, following this link ActiveMQ OutOfMemory Unable to create more threads

+2
source

. , , . , , , , , .

, , . , , .

+1

Source: https://habr.com/ru/post/1723946/


All Articles