Aditya
Aditya

Reputation: 1043

Spring Batch difference between pageSize and commit-interval

Whats the relationship/difference between Spring-Batch Reader 'pageSize' property and Writer 'commit-interval'.

I may be wrong but I see a pattern in my application that for every pageSize exceeded I get see one commit being made. Is this true.?

Thanks

Upvotes: 6

Views: 13111

Answers (2)

andreadi
andreadi

Reputation: 1965

Commit interval determines how many items will be processed in a Chunk.

Page size determines how many items will be fetched every time it is needed.

Depending on the numbers you set, the behavior may be the one you describe. They are used for optimization.

Upvotes: 4

Michael Minella
Michael Minella

Reputation: 21493

The commit-interval defines how many items are processed within a single chunk. That number of items are read, processed, then written within the scope of a single transaction (skip/retry semantics not withstanding).

The page-size attribute on the paging ItemReader implementations (JdbcPagingItemReader for example) defines how many records are fetched per read of the underlying resource. So in the JDBC example, it's how many records are requested with a single hit to the DB.

While there is no direct correlation between the two attributes, it's typically considered a good idea to make them match, however they independently provide two knobs you can turn to modify the performance of your application.

With regards to your direct question, if you have the page-size set to the same as the commit-interval, then yes, I'd expect a single commit for each page.

Upvotes: 15

Related Questions