【问题标题】:Message processing stalls/pauses for a brief period randomly in spring integration消息处理在 Spring 集成中随机暂停/暂停一小段时间
【发布时间】:2019-06-21 16:35:52
【问题描述】:

我有一个使用 spring 集成框架进行消息处理的应用程序(网关 -> 转换 -> 服务激活器)。我面临的问题之一是处理消息有相当长的延迟,从几毫秒到几秒不等。滞后并不一致,似乎消息被搁置并一次处理。

我尝试使用 YourKit 分析应用程序,但找不到任何死锁或阻塞的线程。打开 org.springframework.integration 的调试日志也没有提供太多信息。这是spring集成xml:

    <int:gateway service-interface="com.test.MessageGateway"
            id="msggateway" default-request-channel="msginputchannel" />

    <int:channel id="msginputchannel">
            <int:queue capacity="5000" />
    </int:channel>

    <int:bridge id="msginputbridge" input-channel="msginputchannel" output-channel="msgchannel">
            <int:poller fixed-delay="100"/>
    </int:bridge>

    <int:channel id="msgchannel">
            <int:queue capacity="5000" />
    </int:channel>

    <int:transformer input-channel="msgchannel"
            output-channel="msgPubSubchannel" id="msgtransformer" ref="msgserializer" method="serialzeTo" >
            <int:poller fixed-delay="100"  />
    </int:transformer>

    <int:publish-subscribe-channel id="msgPubSubchannel" />

    <int:bridge id="msgQueueSystembridge" input-channel="msgPubSubchannel" output-channel="msgQueueSystemqueuechannel"/>
    <int:channel id="msgQueueSystemqueuechannel">
            <int:queue capacity="5000"/>
    </int:channel>

    <int:service-activator id="msgQueueSystempublisher" ref="msgQueueSystemadapter" input-channel="msgQueueSystemqueuechannel" method="publish" >
            <int:poller fixed-delay="100"/>
    </int:service-activator>

    <int:bridge id="msgbridge" input-channel="msgPubSubchannel" output-channel="msgFileSystemchannel"/>
    <int:channel id="msgFileSystemchannel">
            <int:queue capacity="5000"/>
    </int:channel>

    <int:service-activator id="msgfilewriter" ref="msgadapter" input-channel="msgFileSystemchannel" method="publish" >
            <int:poller fixed-delay="100"/>
    </int:service-activator>

关于如何进行调试的任何指针?

【问题讨论】:

    标签: spring spring-integration


    【解决方案1】:

    您使用了大量的QueueChannels,它们的所有轮询任务都基于默认的TaskSheduler,线程池只是10。所以,所有任务只共享这 10 个线程,这对你来说确实可能是一个瓶颈。

    您可以考虑不要在两者之间使用太多队列:我认为没有理由在流程中的所有步骤上排队。

    另一方面,您可以使用集成 spring.integration.taskScheduler.poolSize 属性将池大小增加到所需数量:https://docs.spring.io/spring-integration/docs/current/reference/html/whats-new.html#x51.-global-properties

    【讨论】:

    • 感谢@Artem,基于stackoverflow.com/a/44136105/1257065 添加了桥接+队列通道,以提高我的用例中的性能。我将看一下池大小配置。您能否推荐一些方法来监控消息流并查明确切的瓶颈?
    • 唯一的方法是测量 preSend() 和 postReceive() 日志中所有这些通道上的消息。千分尺指标也有助于监控:docs.spring.io/spring-integration/docs/current/reference/html/…
    • &gt;were added based on this - 关键是不需要在每个通道上进行线程切换,您通常只需要一个这样的通道,除非流量很大处理复杂性。
    • @ArtemBilan - 很抱歉延迟回来。我有多个这样的 spring 集成管道(xmls)在单个 jvm 中运行。是否会为每个管道独立创建默认 TaskSheduler,还是每个进程一个?另外,能否请您提供一份有助于 XML 配置的文档?
    • 我错过了日志条目,[org.springframework.integration.config.DefaultConfiguringBeanFactoryPostProcessor] No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created 我在上下文中添加了一个 bean &lt;task:scheduler id="taskScheduler" pool-size="50"/&gt; 以增加池大小。
    猜你喜欢
    • 1970-01-01
    • 2012-01-13
    • 1970-01-01
    • 2011-12-23
    • 2012-03-25
    • 2011-06-21
    • 1970-01-01
    • 2015-06-12
    • 1970-01-01
    相关资源
    最近更新 更多