2017-05-05 43 views
0

我正在使用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; 
} 

回答

1

MultiResourcePartitioner爲每個資源創建一個分區。分區創建過程本身非常快(即分區程序非常快地返回executioncontext映射),但Spring Batch需要花費大量時間來填充相應的元數據數據庫表,並且一旦分區數量超過100個,它就變得非常緩慢(這是我個人的經驗)。

按只回答here,他們做了一些改進,但我使用的最新版本,其分區很慢超過100

this了。

我認爲,除非您準備好自己重寫一堆API代碼,否則除了減少分區數量外,沒有其他選擇。

+0

我使用'spring.batch.initializer.enabled = false'和'MapJobRepository',因此只在內存中存儲任何元數據。無論如何,批處理作業中的「spring-batch stuff」似乎會減慢速度(對於我的30k文件,我有30k個分區;但是我必須堅持使用「Partitioner」,因爲我必須爲每個文件定義輸出文件名在輸入)。所以可能我不得不在這裏放棄'春季批次'。 – membersound

0

我使用自定義分配器,因爲在默認分配器(https://github.com/spring-projects/spring-batch/blob/master/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/SimpleStepExecutionSplitter.java)中,您爲每個StepExecution調用jobRepository.getLastStepExecution。我不使用spring-batch的可重啓性,所以我可以寫我自己的分離器。現在,步驟初始化需要幾秒鐘的時間來處理數千個文件(在幾分鐘之前)

+0

這應該是一條評論 –

相關問題