【问题标题】:Apache Artemis - Apache Camel threaded consumer gets slow over timeApache Artemis - Apache Camel 线程消费者随着时间的推移变得缓慢
【发布时间】:2021-05-21 00:08:08
【问题描述】:

我正在运行 Apache Artemis Broker 2.14.0。下面是消费者连接配置:

<beans
   xmlns="http://www.springframework.org/schema/beans"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-3.1.xsd
      http://www.springframework.org/schema/jee
      http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
      http://camel.apache.org/schema/spring
      http://camel.apache.org/schema/spring/camel-spring.xsd">
      
   <bean class="com.test.CustomProcessBean" id="CustomProcessBean" scope="prototype"/>
   
   <bean id="jmsCF" class="org.apache.qpid.jms.JmsConnectionFactory">
      <property name="remoteURI"  value="ampq://myhost:5672"/>
   </bean>
   
   <bean id="jmsPooledCF" class="org.messaginghub.pooled.jms.JmsPoolConnectionFactory" init-method="start" destroy-method="stop">
      <property name="maxConnections" value="3" />
      <property name="connectionFactory" ref="jmsCF" />
   </bean>
   
   <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
      <property name="connectionFactory" ref="jmsPooledCF" />
      <property name="concurrentConsumers" value="5" />
      <property name="maxConcurrentConsumers" value="10" />
   </bean>
   
   <bean id="jms" class="org.apache.camel.component.amqp.AMQPComponent">
      <property name="configuration" ref="jmsConfig" />
      <property name="transacted" value="true" />
   </bean>
   
   <bean id="errHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder">
      <property name="deadLetterUri" value="jms:queue:customDLQ"/>
      <property name="redeliveryPolicy" ref="customRedeliveryPolicyConfig"/>
   </bean>
   
   <bean id="customRedeliveryPolicyConfig" class="org.apache.camel.processor.RedeliveryPolicy">
      <property name="maximumRedeliveries" value="3"/>
      <property name="redeliveryDelay" value="8000"/>
   </bean>
   
   <camelContext id="camel"
      xmlns="http://camel.apache.org/schema/spring">
      <endpoint id="etams" uri="jms:queue:test-queue" />
      <route errorHandlerRef="errHandler" >
         <from uri="ref:etams"/>
         <convertBodyTo type="java.lang.String" />
         <threads id="threadedprocess" maxQueueSize="5" poolSize="5" maxPoolSize="5" customId="true" >
            <bean ref="CustomProcessBean" method="processMessage"/>
         </threads>
      </route>
   </camelContext>
   
</beans>

从路由开始,每秒处理约 100 条消息。随着时间的推移(约 6 小时),它下降到每秒约 25 条消息。

从 Artemis Web 控制台的“消费者”选项卡中,我注意到每个会话都经常关闭和创建。

从代理端我们提供了足够的内存 12G。代理在启用持久性的情况下运行,并且传入的消息大小小于 5kb。

骆驼threads 是否会随着时间的推移尝试创建更多会话?这是反模式吗?这是消费者处理消息超时缓慢的原因吗?当我不在配置中使用 Camel threads(即只是 &lt;bean ref="CustomProcessBean ...&gt;)时,我注意到创建的会话 ID 没有改变。这可能完全基于用例,但重新创建会话是否会对代理造成性能压力?

【问题讨论】:

  • 我推断,每当刷新消费者选项卡时,哈希 ID 值都会发生变化。
  • 我了解消费者(使用 AMQP 客户端)配置正在重新创建会话。当我不在配置中使用骆驼线程时(只是
    代理在启用持久性的情况下运行,并且传入的消息大小小于 5kb。
  • 一开始是每秒约 100 条消息,随着时间的推移(约 6 小时),它是每秒约 25 条消息。一个观察结果是消费者数量一直在 1 到 10 之间变化(10 设置为 maxconcurrentconsumer 值)Camel 线程仅在从队列中获取消息后才使用。
  • 如果你去掉 Camel threads 的使用,你还看到性能下降吗?此外,目前还不清楚为什么您首先开始使用threads

标签: apache-camel activemq-artemis spring-camel


【解决方案1】:

我遇到了同样的问题,并通过将 JMS 端点中的cacheLevelName 选项设置为CACHE_CONSUMER 来解决它。通过启用transacted 选项,您最终将缓存级别设置为CACHE_NONE

本节将更好地为您解释:JMS Component - TRANSACTIONS AND CACHE LEVELS

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签