我正在使用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);
}
}
}
所以我的最好的辦法是把更多的聽衆那裏的主人? – 2009-11-26 00:08:28
如果這就是你的數據告訴你的,那麼是的。告訴發生什麼事的唯一方法是觀察隊列並衡量聽衆。 – duffymo 2009-11-26 12:20:36