【问题标题】:Performance problem with camel "activemq component"骆驼“activemq组件”的性能问题
【发布时间】:2019-09-24 22:50:04
【问题描述】:

我尝试使用 ActiveMQ 组件(在 Spring-Boot 内),但结果有些奇怪 结果。

1- 我从 SEDA 向 destinationQueue 发送了 2000 条消息

我是这样做的:

from("file:G:/highlight").to("seda:warehouse");
// took less than a millisecond to complete



from("seda:warehouse?concurrentConsumers=20").to("activemq:queue:destinationQueue") 
// Completion time : 58 seconds

Completion time : 58 seconds

2- 现在我尝试使用来自destinationQueue 的这些文件 这就是我要这样做的方式:

        from("activemq:queue:line1").process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                System.out.println(exchange.getIn().getBody(String.class));
            }
        });  
// The completion time : around 1 second!
The completion time : around 1 second!

所以我的问题是:

1- 为什么我将文件发送到队列时速度很慢?但我可以消费那些 消息如此之快(在这个测试中,它快了 50 倍以上)!!!

  • 我确实在笔记本电脑上消费和生产。

任何帮助将不胜感激:))

【问题讨论】:

  • 恕我直言:当您向 ActiveMQ 队列发送消息时,会将它们放入数据库中。数据库位于您的硬盘驱动器上(瓶颈)。从数据库读取比写入要快。当然你也可以使用 ActiveMQ 的设置
  • 疯狂猜测(略有不同):基于磁盘的源(文件(...))与内存读取。使用 System.out.println 处理器检查 from("file...") 需要多长时间。

标签: java apache-camel activemq


【解决方案1】:

感谢@Alexey-yakunin,我找到了它:)

当您使用 ActiveMQ 时,如果您的目的地是“队列”,那么生成消息的速度到 队列比从队列中消费要慢得多。 这是因为,就像@Alexey-yakunin 所说的那样“当您向 ActiveMQ 队列发送消息时,您将它们放入数据库中。数据库位于您的硬盘驱动器上(瓶颈)。从数据库读取比写入它更快” .

所以为了证明这个理论,我做了这个测试:

(我没有将消息发送到queue,而是将它们发送到topic,没有任何持久订阅者)

No durable subscribers to the topic == No databse

        from("file:G:/highlight").to("activemq:topic:newVersion");
        from("activemq:topic:newVersion").process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                long time = System.currentTimeMillis();
                Date date = new Date(time);
                System.out.println(date);

            }
        });

对于2000 messages,只需要3 seconds 就可以产生和消费所有消息。

这些也是我在 spring boot application.properties 中设置的选项,以便充分利用 activemq:

camel.component.activemq.broker-u-r-l=tcp://localhost:61616

// By default it is set to false so make sure you set this to true
camel.component.activemq.use-pooled-connection=true 

camel.component.activemq.transacted=false

//Remember, the messages will be lost if the broker crashes or is restarted.
camel.component.activemq.delivery-persistent=false

camel.component.activemq.wait-for-provision-correlation-to-be-updated-thread-sleeping-time=50

还有另外两个选项可以刺激你改变它们的价值,但我找到了它们 充其量设置为默认值时:

camel.component.activemq.concurrent-consumers
camel.component.activemq.max-concurrent-consumers

就是这样:))

【讨论】:

  • 值得注意的是,使用非持久消息(通过camel.component.activemq.delivery-persistent=false 意味着如果代理崩溃或重新启动,消息将丢失。此外,如果您希望从 ActiveMQ 代理结帐中获得最佳性能ActiveMQ Artemis。它的性能比 5.x 代理要好得多,尤其是在高并发用例中。
  • @JustinBertram,你是绝对正确的。不同的上下文需要不同的设置。在这里,我试图证明为什么生产到队列比从中消费慢得多的原因,并且在我的示例中,我说“非持久主题”只是为了删除数据库。当然还有比 ActiveMQ 更好的选择,比如 Rabbit 和 Kafka。
  • Rabbit 或 Kafka 是否是 ActiveMQ Artemis 的更好选择,当然还有待商榷。如果您关心数据的性能和高可用性,那么this article 可能会有所帮助。
猜你喜欢
  • 1970-01-01
  • 2015-05-05
  • 2013-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多