2009-11-25 81 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