gpt4 book ai didi

java - 如何优化activemq

转载 作者:搜寻专家 更新时间:2023-11-01 03:14:44 25 4
gpt4 key购买 nike

我正在使用 ActiveMQ 模拟 Java 中的重载服务器。主要是它没问题,但是当我收到超过 600 个请求时,事情就变得糟糕了!

我认为瓶颈是我的主服务器,也就是下面这个人。我已经在重用连接并创建各种 session 来使用来自客户端的消息。就像我说的,我在每个连接上使用大约 50-70 个 session ,重新利用连接和队列。知道我可以重用/优化下面的组件/监听器吗?

架构如下:

* = 各种

Client ---> JMS MasterQueue ---> * Master ---> JMS SlavaQueue ---> * SlaveQueue

主要是我为每个 Master session 创建一个临时队列 --> 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);
}
}
}

最佳答案

好吧,经过一些阅读我发现了如何优化。

我们应该重用一些 session 变量,比如sender和tempqueue。而不是创建新的。

另一种方法是降低 Java 中线程的堆栈大小,点击此链接 ActiveMQ OutOfMemory Can't create more threads

关于java - 如何优化activemq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1800774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com