Spring文件入站通道适配器速度变慢

时间:2018-06-12 13:05:54

标签: spring-integration

我有一个spring-integration流程,它以一个由事务轮询器激活的文件入站通道适配器开始(tx由atomikos处理)。 处理文件中的文本,消息在流中向下发送,直到它被发送到其中一个JMS队列(JMS出站通道适配器)。 在中间,嵌套事务中有一些数据库写入。 该系统旨在全天候运行。

发生单个消息流,逐渐减慢,当我调查时,我发现负责增加延迟的阶段是从文件系统读取。

下面是整合流程的第一部分:

<logging-channel-adapter id="logger" level="INFO"/>
<transaction-synchronization-factory id="sync-factory">
    <after-commit expression="payload.delete()" channel="after-commit"/>
</transaction-synchronization-factory>
<service-activator input-channel="after-commit" output-channel="nullChannel" ref="tx-after-commit-service"/>



<!-- typeb inbound from filesystem -->
<file:inbound-channel-adapter id="typeb-file-inbound-adapter"
                              auto-startup="${fs.typeb.enabled:true}"
                              channel="typeb-inbound"
                              directory="${fs.typeb.directory.in}"
                              filename-pattern="${fs.typeb.filter.filenamePattern:*}"
                              prevent-duplicates="${fs.typeb.preventDuplicates:false}" >
    <poller id="poller"
            fixed-delay="${fs.typeb.polling.millis:1000}"
            max-messages-per-poll="${fs.typeb.polling.numMessages:-1}">
        <transactional synchronization-factory="sync-factory"/>
    </poller>
</file:inbound-channel-adapter>
<channel id="typeb-inbound">
    <interceptors>
        <wire-tap channel="logger"/>
    </interceptors>
</channel>

我读了一些与prevent-duplicates选项相关的问题,该选项存储了所见文件的列表,但事实并非如此,因为我将其关闭了。 我不认为它可能与过滤器(文件名模式)有关,因为我在配置中使用的表达式(* .RCV)很容易应用,输入文件夹不包含很多文件(少而不是100)同时。

但是,随着时间的推移,有些东西会逐渐使文件系统的读取速度变慢,从几毫秒到超过3秒,在几天的正常运行时间内。

任何提示?

2 个答案:

答案 0 :(得分:0)

您应该在处理完文件后删除或移动文件;否则必须重新扫描整个目录。

在较新的版本中,您可以使用效率更高的WatchServiceDirectoryScanner

但清理旧文件仍是最佳做法。

答案 1 :(得分:0)

最后我找到了解决方案。 问题与我正在使用的特定版本的Spring(4.3.4)有关,该版本受我尚未发现的错误的影响。 问题在于有关DefaultConversionService以及使用converterCache的问题(有关更多详细信息,请参见https://jira.spring.io/browse/SPR-14929)。 升级到最新版本已解决。

相关问题