English 中文(简体)
How to optimize activemq
原标题:

I m using ActiveMQ on a simulation of overloading servers in Java. And mainly it goes ok, but when I get over 600 requests the thing just go WTF!

I think the bottleneck is my Master Server which is this guy below. I m already reusing the connection and creating various sessions to consume messages from clients. Like I said, I m using about 50-70 sessions per connection, reutilizing the connection and queue. Any idea of what I can reuse/optimize of my components/listener below?

The architecture is the follow:

* = various

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

Mainly I m creating a Temp Queue for each session of Master --> Slave communication, is that a big problem on performance?

/**
 * 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 s 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);
        }
    }
}
最佳回答

Well, After some reading I found out how to optimize.

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

Another approach is put the stack size for thread in Java lower, following this link ActiveMQ OutOfMemory Can t create more threads

问题回答

It could have to do with the configuration of the listener thread pool. It could be that up to a certain threshold number of requests per second the listener is able to keep up and process the incoming requests in a timely way, but above that rate it starts to fall behind. it depends on the work done for each incoming request, the incoming request rate, the memory and CPU available to each listener, and the number of listeners allocated.

If this is true, you should be able to watch the queue and see when the number of incoming messages start to back up. That s the point at which you need to increase the resources and number of listeners to process efficiently.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签