我正在使用Partitioner
来并行化*.csv
文件的导入。该文件夹中有大约30k个文件。在Spring-Batch中使用分区程序的初始化时间过长?
问题:作业初始化大约需要1-2个小时,直到所有文件都设置好。瓶颈在SimpleStepExecutionSplitter.split()
。
问题:步骤初始化需要多少时间是正常吗?或者我能否以某种方式改进它?
@Bean
public Step partitionStep(Partitioner partitioner) {
return stepBuilderFactory.get("partitionStep")
.partitioner(step())
.partitioner("partitioner", partitioner)
.taskExecutor(taskExecutor())
.build();
}
@Bean
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(4); //run import always with 4 parallel files
taskExecutor.setMaxPoolSize(4);
taskExecutor.afterPropertiesSet();
return taskExecutor;
}
@Bean
public Partitioner partitioner() throws IOException {
MultiResourcePartitioner p = new MultiResourcePartitioner();
p.setResources(new PathMatchingResourcePatternResolver().getResources("mypath/*.csv"));
return p;
}
我使用'spring.batch.initializer.enabled = false'和'MapJobRepository',因此只在内存中存储任何元数据。无论如何,批处理作业中的“spring-batch stuff”似乎会减慢速度(对于我的30k文件,我有30k个分区;但是我必须坚持使用“Partitioner”,因为我必须为每个文件定义输出文件名在输入)。所以可能我不得不在这里放弃'春季批次'。 – membersound