2009-11-25 80 views
3

我正在使用ActiveMQ模拟Java中的服务器重载。主要是它没问题,但是当我收到600多个请求时,事情就会变成WTF!如何优化activemq

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

的体系结构是如下:

* =各种

客户---> JMS MasterQueue ---> *主---> JMS SlavaQueue ---> * SlaveQueue

主要是我为每个Master - > Slave通信创建一个Temp Queue,这是性能上的一个大问题吗?

/** 
* 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); 
     } 
    } 
} 

回答

2

那么,经过一些阅读后,我发现如何优化。

我们应该重用一些会话变量,例如sender和tempqueue。而不是创造新的。

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

1

它可能与侦听线程池的配置有关。可能是,每秒钟的请求数量达到一定的阈值,即听众能够及时处理传入的请求,但超过该速率则开始落后。它取决于为每个传入请求完成的工作,传入请求速率,每个侦听器可用的内存和CPU以及分配的侦听器数量。

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

+0

所以我的最好的办法是把更多的听众那里的主人? – 2009-11-26 00:08:28

+0

如果这就是你的数据告诉你的,那么是的。告诉发生什么事的唯一方法是观察队列并衡量听众。 – duffymo 2009-11-26 12:20:36