我在用 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);
}
}
}