[英]What are the benchmarks for JMS sending messages to ActiveMQ?
我正在開發一個 spring 啟動應用程序,該應用程序將從多個聊天平台接收消息。 我使用 JMS 和 ActiveMQ 作為代理。
以下是用例中涉及的步驟:
我已經運行了負載測試來評估性能,這里是第 1 步和第 4 步的結果。
結果:
第 1 步和第 4 步是否有任何基准? 第 1 步和第 4 步的最佳可實現數字是多少? 如何優化這兩個步驟?
在上述用例中需要消息持久性。
ActiveMQ 連接配置:
prefetchPolicy.queuePrefetch=1
prefetchPolicy.queueBrowserPrefetch=500
prefetchPolicy.durableTopicPrefetch=100
prefetchPolicy.topicPrefetch=32766
alwaysSessionAsync=true
copyMessageOnSend=false
ActiveMQ 隊列的生產者:
public JmsProducer initProducer(String correlationId) throws JMSException {
Session clientSession = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue destination = clientSession.createQueue(Constants.INBOUND_MESSAGE_QUEUE);
MessageProducer producer = clientSession.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
return new JmsProducer(producer, clientSession);
}
ActiveMQ 隊列的發布方法:
public void publish(String message, String jmsType, String correlationId) throws JMSException {
long startTime = System.currentTimeMillis();
TextMessage textMessage = producerSession.createTextMessage(message);
textMessage.setJMSType(jmsType);
textMessage.setJMSCorrelationID(correlationId);
producer.send(textMessage);
logger.debug("Time taken by publish: {}", System.currentTimeMillis() - startTime);
}
ActiveMQ 主題的生產者:
private void setPublisher() throws JMSException {
publisherSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic destination = publisherSession.createTopic(this.topicName);
publisher = publisherSession.createProducer(destination);
publisher.setDeliveryMode(DeliveryMode.PERSISTENT);
}
ActiveMQ 主題的發布方法:
public void publish(Serializable message, String event, String correlationId)
throws JsonProcessingException, JMSException {
long startTime = System.currentTimeMillis();
TextMessage messageToSend =
publisherSession.createTextMessage(new ObjectMapper().writeValueAsString(message));
messageToSend.setJMSType(event);
messageToSend.setJMSCorrelationID(correlationId);
publisher.send(messageToSend);
logger.debug("Time taken by publish: {}", System.currentTimeMillis() - startTime);
}
設計基准遠遠超出了 scope 任何可以通過 SO 帖子合理完成的事情。 我將分享我多年來收集的一些技巧,以幫助您獲得一些可行的數字。
每秒測量消息數只是整體視圖的一部分。 您真的應該查看吞吐量(即 MB/s - 消息大小 * 消息速率 = 吞吐量)和延遲。
將隊列預取增加到 1000 左右。這是減少延遲的巨大性能提升,也是 ActiveMQ 優於許多其他代理的重要部分。
由於延遲而不是代理容量,運行發送到一個隊列的單線程連接將達到頂峰。 添加更多線程——32、64、128、256 等,以更好地了解代理可以做什么。
在 ConnectionFactories 上禁用 watchTopicAdvisories。
調整 KahaDB 可以顯着提高吞吐量。 這是超級復雜且依賴於工作負載的。
分別對磁盤和網絡進行基准測試。 然后與您的 ActiveMQ 結果進行比較。 您應該在 CPU 之前在磁盤或網絡上達到頂峰。
為具有大量客戶端針對相同隊列的工作負載添加更多 CPU 與更多代理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.