【问题标题】:How to optimize activemq如何优化activemq
【发布时间】:2010-12-20 12:32:35
【问题描述】:

我在用 Java 模拟过载服务器时使用 ActiveMQ。主要是没问题,但是当我收到超过 600 个请求时,事情就发生了 WTF!

我认为瓶颈是我的主服务器,也就是下面的这个人。我已经在重用连接并创建各种会话来使用来自客户端的消息。就像我说的,我每个连接使用大约 50-70 个会话,重新利用连接和队列。知道我可以在下面重用/优化我的组件/侦听器吗?

架构如下:

* = 各种

客户端 ---> JMS MasterQueue ---> * Master ---> JMS SlavaQueue ---> * SlaveQueue

主要是我为Master的每个会话创建一个Temp Queue --> 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);
        }
    }
}

【问题讨论】:

    标签: java performance jakarta-ee jms activemq


    【解决方案1】:

    嗯,经过一番阅读,我发现了如何优化。

    我们应该重用一些会话变量,例如发送者和临时队列。而不是创建新的。

    另一种方法是降低 Java 中线程的堆栈大小,如下链接 ActiveMQ OutOfMemory Can't create more threads

    【讨论】:

      【解决方案2】:

      这可能与侦听器线程池的配置有关。可能是在每秒达到一定阈值的请求数时,侦听器能够及时跟上并处理传入的请求,但高于该速率它开始落后。这取决于每个传入请求所做的工作、传入请求速率、每个侦听器可用的内存和 CPU 以及分配的侦听器数量。

      如果是这样,您应该能够观察队列并查看传入消息的数量何时开始备份。这就是您需要增加资源和侦听器数量以有效处理的点。

      【讨论】:

      • 所以我最好的办法是在master上放更多的听众?
      • 如果这是您的数据告诉您的,那么是的。判断正在发生的事情的唯一方法是观察队列并测量听众。
      猜你喜欢
      • 1970-01-01
      • 2011-03-11
      • 2012-02-09
      • 2013-01-02
      • 1970-01-01
      • 2014-05-23
      • 1970-01-01
      • 2011-12-18
      • 2011-04-09
      相关资源
      最近更新 更多