ActiveMQ Artemis 和 Spring JmsTemplate 的性能问题
Performance issues with ActiveMQ Artemis and Spring JmsTemplate
在使用 ActiveMQ Artemis 代理和我的 Spring 启动应用程序进行一些负载测试时,我遇到了性能问题。
我正在做的是发送例如使用 JMSeter 每秒向代理发送 12,000 条消息,应用程序接收它们并将它们保存到数据库中。那很好用。但是当我通过过滤器机制扩展我的应用程序时,它在保存到数据库后转发事件,使用 jmsTemplate.send(destination, messageCreator)
返回给代理它变得非常慢。
我第一次使用 ActiveMQ 5.x 并且这个机制运行良好。在那里你可以配置 ActiveMQConnectionFactory
和 setAsyncSend(true)
来调整性能。对于 ActiveMQ Artemis ConnectionFactory
实现,没有这种可能性。是否有另一种方法可以像 ActiveMQ 5.x 那样调整性能?
我正在使用 Apache ActiveMQ Artemis 2.16.0(但也尝试过 2.15.0)、artemis-jms-client 2.6.4 和 Spring Boot 1.5.16.RELEASE.
首先要注意的是,您在使用 Spring 的 JmsTemplate 发送消息时需要非常小心,因为它采用了一种众所周知的反模式,这种模式确实会降低性能。它实际上会为它发送的 每个 消息创建一个新的 JMS 连接、会话和生产者。我推荐你 use a connection pool like this one which is based on the ActiveMQ 5.x connection pool implementation but now supports JMS 2. For additional details about the danger of using JmsTemplate see the ActiveMQ documentation. This is also discussed in an article from Pivotal(即 Spring 的“所有者”)。
这里的第二点是,您可以 调整持久性 JMS 消息是否同步发送或不使用 blockOnDurableSend
URL 属性 , 例如:
tcp://localhost:61616?blockOnDurableSend=false
这将确保异步发送持久 JMS 消息。 ActiveMQ Artemis documentation.
中对此进行了进一步讨论
在使用 ActiveMQ Artemis 代理和我的 Spring 启动应用程序进行一些负载测试时,我遇到了性能问题。
我正在做的是发送例如使用 JMSeter 每秒向代理发送 12,000 条消息,应用程序接收它们并将它们保存到数据库中。那很好用。但是当我通过过滤器机制扩展我的应用程序时,它在保存到数据库后转发事件,使用 jmsTemplate.send(destination, messageCreator)
返回给代理它变得非常慢。
我第一次使用 ActiveMQ 5.x 并且这个机制运行良好。在那里你可以配置 ActiveMQConnectionFactory
和 setAsyncSend(true)
来调整性能。对于 ActiveMQ Artemis ConnectionFactory
实现,没有这种可能性。是否有另一种方法可以像 ActiveMQ 5.x 那样调整性能?
我正在使用 Apache ActiveMQ Artemis 2.16.0(但也尝试过 2.15.0)、artemis-jms-client 2.6.4 和 Spring Boot 1.5.16.RELEASE.
首先要注意的是,您在使用 Spring 的 JmsTemplate 发送消息时需要非常小心,因为它采用了一种众所周知的反模式,这种模式确实会降低性能。它实际上会为它发送的 每个 消息创建一个新的 JMS 连接、会话和生产者。我推荐你 use a connection pool like this one which is based on the ActiveMQ 5.x connection pool implementation but now supports JMS 2. For additional details about the danger of using JmsTemplate see the ActiveMQ documentation. This is also discussed in an article from Pivotal(即 Spring 的“所有者”)。
这里的第二点是,您可以 调整持久性 JMS 消息是否同步发送或不使用 blockOnDurableSend
URL 属性 , 例如:
tcp://localhost:61616?blockOnDurableSend=false
这将确保异步发送持久 JMS 消息。 ActiveMQ Artemis documentation.
中对此进行了进一步讨论