Skip to content

Performance issues in SimpleJobRepository.getStepExecutionCount(JobInstance jobInstance, String stepName) #3657

Closed
@bcubk

Description

@bcubk

Hi Spring-Batch Team,

couple days ago, we noticed a high amount of CPU utilization in our Spring Batch application. Our batch job contains a high amount of job steps. We debugged the code and localized a small issue in class SimpleJobRepository.getStepExecutionCount(JobInstance jobInstance, String stepName). Here the implementation:

/**
* @return number of executions of the step within given job instance
*/
@Override
public int getStepExecutionCount(JobInstance jobInstance, String stepName) {
	int count = 0;
	List<JobExecution> jobExecutions = jobExecutionDao.findJobExecutions(jobInstance);
	for (JobExecution jobExecution : jobExecutions) {
		stepExecutionDao.addStepExecutions(jobExecution);
		for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
			if (stepName.equals(stepExecution.getStepName())) {
				count++;
			}
		}
	}
	return count;
}

This retrieves all StepExecutions for all JobExecutions of a particular JobInstance and counts the StepExecutions in a for-loop. We changed this method and executing a count in the underlying database which solved our CPU problem. Is this a good solution? If not, why? Of course, we would contribute our fix 👍

Thanks in advance and kind regards
Baris

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions