大型输入文件的 Mule 4 批处理

Mule 4 Batch Process on large input file

我有一个巨大的文件,可以包含几十万到五百万条记录。它的制表符分隔文件。我需要从 ftp 位置读取文件,对其进行转换,最后将其写入 FTP 位置。

我打算使用 FTP 连接器获取可重复流并将其放入 mule 批处理中。在 mule 批处理过程中,想法是使用批处理步骤来转换记录,最后在批处理聚合中 FTP 以追加模式将文件写入目标,一次 100 条记录。

Q1。这是一个好方法还是有更好的方法?

Q2。 mule 批处理加载和分派阶段如何工作(https://docs.mulesoft.com/mule-runtime/4.3/batch-processing-concept#load-and-dispatch)在分派 mule 批处理实例之前,是否等待整个数百万条记录流被读取到内存中?

Q3。在批量聚合中执行 FTP 写入时,并行线程有可能同时开始将内容附加到 FTP,从而破坏记录。那是可以避免的吗。我读到了文件锁 (https://docs.mulesoft.com/ftp-connector/1.5/ftp-write#locks) 。我的假设是它只会引发文件锁定异常,而不必等待以追加模式写入 FTP。

Q1. Is this a good approach or is there some better approach?

参见问题 3 的回答,这可能不适合您。您可以改为使用 foreach 并按顺序处理文件,但这会显着增加处理时间。

Q2. How does mule batch load and dispatch phase work (https://docs.mulesoft.com/mule-runtime/4.3/batch-processing-concept#load-and-dispatch ) Is it waiting for entire stream of millions of records to be read in memory before dispatching a mule batch instance ?

批处理不会在内存中加载大量记录,它使用基于文件的队列。是的,它会在开始处理之前加载队列中的所有记录。

Q3. While doing FTP write in batch aggregate there is a chance that parallel threads will start appending content to FTP at same time thereby corrupting the records. Is that avoidable. I read about File locks (https://docs.mulesoft.com/ftp-connector/1.5/ftp-write#locks) . My assumption is it will simply raise File lock exception and not necessarily wait to write FTP in append mode

如果文件已被锁定,文件写入操作将抛出 FILE:FILE_LOCK 错误。请注意,Mule 4 不通过异常管理错误,它使用 Mule 错误。

如果您使用 DataWeave 平面文件来解析输入文件,请注意它会将文件加载到内存中并使用比文件本身多得多的内存来处理它,因此您可能会遇到内存不足的情况还是出错了。