-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Batch2 Remove Paging Iterator #6783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Capt-Mac
wants to merge
12
commits into
master
Choose a base branch
from
batch2-remove-paging-iterator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
41f832a
modify enqueueReadyChunks without paginator to keep consumers saturated
Capt-Mac 0e8d146
spotless edits
Capt-Mac ef7fc41
update assertion for error count
Capt-Mac 1746795
add catch to prevent infinite looping
Capt-Mac d30575d
changelog and comments
Capt-Mac c9810e1
log warning for missed deadline
Capt-Mac ec01830
convert while to for loop
Capt-Mac 891464c
minute variable for deadline
Capt-Mac 6fa34c5
remove unused import
Capt-Mac 89cc2ac
Update hapi-fhir-storage-batch2/src/main/java/ca/uhn/fhir/batch2/main…
Capt-Mac 4b5b51e
add break when processing deadline is met
Capt-Mac 41664ec
Merge branch 'batch2-remove-paging-iterator' of github.com:hapifhir/h…
Capt-Mac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
...ocs/src/main/resources/ca/uhn/hapi/fhir/changelog/8_2_0/6784-remove-batch2-paginator.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
type: fix | ||
issue: 6783 | ||
title: "The batch2 job processor will no longer use paginator to queue workchunks as 'ready' due to performance bottleneck | ||
around saturation of available workchunk-processors or consumers" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,15 +33,13 @@ | |
import ca.uhn.fhir.batch2.progress.JobInstanceProgressCalculator; | ||
import ca.uhn.fhir.batch2.progress.JobInstanceStatusUpdater; | ||
import ca.uhn.fhir.model.api.IModelJson; | ||
import ca.uhn.fhir.model.api.PagingIterator; | ||
import ca.uhn.fhir.util.Logs; | ||
import ca.uhn.fhir.util.StopWatch; | ||
import org.apache.commons.lang3.time.DateUtils; | ||
import org.slf4j.Logger; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
@@ -266,17 +264,6 @@ private boolean canAdvanceGatedJob(JobInstance theInstance) { | |
return workChunkStatuses.equals(Set.of(WorkChunkStatusEnum.COMPLETED)); | ||
} | ||
|
||
protected PagingIterator<WorkChunkMetadata> getReadyChunks() { | ||
return new PagingIterator<>(WORK_CHUNK_METADATA_BATCH_SIZE, (index, batchsize, consumer) -> { | ||
Pageable pageable = Pageable.ofSize(batchsize).withPage(index); | ||
Page<WorkChunkMetadata> results = myJobPersistence.fetchAllWorkChunkMetadataForJobInStates( | ||
pageable, myInstanceId, Set.of(WorkChunkStatusEnum.READY)); | ||
for (WorkChunkMetadata metadata : results) { | ||
consumer.accept(metadata); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Trigger the reduction step for the given job instance. Reduction step chunks should never be queued. | ||
*/ | ||
|
@@ -292,27 +279,56 @@ private void triggerReductionStep(JobInstance theInstance, JobWorkCursor<?, ?, ? | |
* for processing. | ||
*/ | ||
private void enqueueReadyChunks(JobInstance theJobInstance, JobDefinition<?> theJobDefinition) { | ||
lukedegruchy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Iterator<WorkChunkMetadata> iter = getReadyChunks(); | ||
|
||
int counter = 0; | ||
while (iter.hasNext()) { | ||
WorkChunkMetadata metadata = iter.next(); | ||
|
||
/* | ||
* For each chunk id | ||
* * Move to QUEUE'd | ||
* * Send to topic | ||
* * flush changes | ||
* * commit | ||
*/ | ||
updateChunkAndSendToQueue(metadata); | ||
counter++; | ||
} | ||
ourLog.debug( | ||
"Encountered {} READY work chunks for job {} of type {}", | ||
counter, | ||
theJobInstance.getInstanceId(), | ||
theJobDefinition.getJobDefinitionId()); | ||
// timebox to prevent unusual amount of time updating resources | ||
long minuteMS = 60 * 1000; | ||
long deadline = System.currentTimeMillis() + DateUtils.MILLIS_PER_MINUTE; | ||
boolean done = false; | ||
do { | ||
// Paginator has an issue keeping worker nodes saturated due to processing workloads a page at a time | ||
// PageNumber '0' is hardcoded to re-saturate 10k records to process at a time instead | ||
// Each consecutive request for results will be the next 10k records needing updating (no paging needed) | ||
// Recommend this eventually moves to java stream once architecture supports the change | ||
Pageable pageable = Pageable.ofSize(WORK_CHUNK_METADATA_BATCH_SIZE).withPage(0); | ||
Page<WorkChunkMetadata> results = myJobPersistence.fetchAllWorkChunkMetadataForJobInStates( | ||
pageable, myInstanceId, Set.of(WorkChunkStatusEnum.READY)); | ||
if (results.isEmpty()) { | ||
done = true; | ||
} | ||
int counter = 0; | ||
|
||
if (!done) { | ||
for (WorkChunkMetadata metadata : results) { | ||
/* | ||
* For each chunk id | ||
* * Move to QUEUE'd | ||
* * Send to topic | ||
* * flush changes | ||
* * commit | ||
*/ | ||
updateChunkAndSendToQueue(metadata); | ||
counter++; | ||
} | ||
} | ||
// catch to prevent unlimited looping | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trivial: This counting and check probably isn't required since you do the empty check above. The next page after a short result will be empty. |
||
if (counter < WORK_CHUNK_METADATA_BATCH_SIZE) { | ||
done = true; | ||
} | ||
ourLog.debug( | ||
"Encountered {} READY work chunks for job {} of type {}", | ||
counter, | ||
theJobInstance.getInstanceId(), | ||
theJobDefinition.getJobDefinitionId()); | ||
|
||
// Log warning and exit if deadline is exceeded | ||
if (System.currentTimeMillis() >= deadline) { | ||
ourLog.warn( | ||
"Deadline exceeded while processing job {} of type {}. Some chunks may not have been processed.", | ||
theJobInstance.getInstanceId(), | ||
theJobDefinition.getJobDefinitionId()); | ||
Capt-Mac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
break; | ||
} | ||
|
||
} while (!done); | ||
} | ||
|
||
/** | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.