简体   繁体   English

如何优化activemq

[英]How to optimize activemq

I'm using ActiveMQ on a simulation of overloading servers in Java. 我正在使用ActiveMQ模拟Java中的服务器重载。 And mainly it goes ok, but when I get over 600 requests the thing just go WTF! 主要是好的,但是当我收到超过600个请求时,就会发生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. 就像我说的,我每个连接使用大约50-70个会话,重用连接和队列。 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 客户端---> 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? 主要是我为Master的每个会话创建一个临时队列 - > Slave通信,这是性能上的一个大问题吗?

/**
 * 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. 我们应该重用一些会话变量,例如sender和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 另一种方法是将Java中的线程的堆栈大小降低,遵循此链接ActiveMQ OutOfMemory无法创建更多线程

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. 它取决于为每个传入请求所做的工作,传入请求速率,每个侦听器可用的内存和CPU以及分配的侦听器数量。

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. 这就是您需要增加资源和有效处理的侦听器数量的点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM