Skip to content

Improve performance when polling replies in MessageChannelPartitionHandler #4135

Closed as not planned
@lcmarvin

Description

@lcmarvin

Currently a for each loop is used in MessageChannelPartitionHandler to poll the partition StepExecutions.

for (Iterator<StepExecution> stepExecutionIterator = split.iterator(); stepExecutionIterator.hasNext();) {
	StepExecution curStepExecution = stepExecutionIterator.next();

	if (!result.contains(curStepExecution)) {
		StepExecution partitionStepExecution = jobExplorer
            .getStepExecution(managerStepExecution.getJobExecutionId(), curStepExecution.getId());

		if (!partitionStepExecution.getStatus().isRunning()) {
			result.add(partitionStepExecution);
		}
	}
}

When there are lots of partition StepExecutions, the method org.springframework.batch.core.explore.JobExplorer#getStepExecution will cause lots of repeated sql query on database. Take a look at the implementation of this method.

	@Nullable
	@Override
	public StepExecution getStepExecution(@Nullable Long jobExecutionId, @Nullable Long executionId) {
		JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId);
		if (jobExecution == null) {
			return null;
		}
		getJobExecutionDependencies(jobExecution);
		StepExecution stepExecution = stepExecutionDao.getStepExecution(jobExecution, executionId);
		getStepExecutionDependencies(stepExecution);
		return stepExecution;
	}

The JobInstance, JobExecution, JobParameters, JobExecutionContext, and StepExecutions of the JobExecution are queried again and again, which can be simplified in my option.

So can we only query the needed StepExecution in this loop? I believe there will be performance improvement if we can simplify the query.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions