我正在使用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