mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-27 08:47:07 +00:00
remove parallelism from non-get batch operations
This commit is contained in:
parent
bc93403364
commit
7dfe628551
@ -205,7 +205,6 @@ public abstract class BaseTransactionProcessor {
|
||||
executor.setThreadNamePrefix("bundle_batch_");
|
||||
executor.setCorePoolSize(myDaoConfig.getBundleBatchPoolSize());
|
||||
executor.setMaxPoolSize(myDaoConfig.getBundleBatchMaxPoolSize());
|
||||
executor.setQueueCapacity(DaoConfig.DEFAULT_BUNDLE_BATCH_QUEUE_CAPACITY);
|
||||
executor.initialize();
|
||||
myExecutor = executor;
|
||||
|
||||
@ -393,38 +392,47 @@ public abstract class BaseTransactionProcessor {
|
||||
List<IBase> requestEntries = myVersionAdapter.getEntries(theRequest);
|
||||
int requestEntriesSize = requestEntries.size();
|
||||
|
||||
// And execute for each entry in parallel as a mini-transaction in its
|
||||
// own database transaction so that if one fails, it doesn't prevent others.
|
||||
// The result is keep in the map to save the original position
|
||||
// Now, run all non-gets sequentially, and all gets are submitted to the executor to run (potentially) in parallel
|
||||
// The result is kept in the map to save the original position
|
||||
List<RetriableBundleTask> getCalls = new ArrayList<>();
|
||||
List<RetriableBundleTask> nonGetCalls = new ArrayList<>();
|
||||
|
||||
CountDownLatch completionLatch = new CountDownLatch(requestEntriesSize);
|
||||
IBase nextRequestEntry = null;
|
||||
for (int i = 0; i < requestEntriesSize; i++) {
|
||||
nextRequestEntry = requestEntries.get(i);
|
||||
long getEntriesSize = requestEntries.stream().filter(entry -> myVersionAdapter.getEntryRequestVerb(myContext, entry).equalsIgnoreCase("GET")).count();
|
||||
CountDownLatch completionLatch = new CountDownLatch((int) getEntriesSize);
|
||||
for (int i=0; i<requestEntriesSize ; i++ ) {
|
||||
IBase nextRequestEntry = requestEntries.get(i);
|
||||
RetriableBundleTask retriableBundleTask = new RetriableBundleTask(completionLatch, theRequestDetails, responseMap, i, nextRequestEntry, theNestedMode);
|
||||
getTaskExecutor().execute(retriableBundleTask);
|
||||
if (myVersionAdapter.getEntryRequestVerb(myContext, nextRequestEntry).equalsIgnoreCase("GET")) {
|
||||
getCalls.add(retriableBundleTask);
|
||||
} else {
|
||||
nonGetCalls.add(retriableBundleTask);
|
||||
}
|
||||
}
|
||||
//Execute all non-gets on calling thread.
|
||||
nonGetCalls.forEach(RetriableBundleTask::run);
|
||||
//Execute all gets (potentially in a pool)
|
||||
getCalls.forEach(getCall -> getTaskExecutor().execute(getCall));
|
||||
|
||||
// waiting for all tasks to be completed
|
||||
// waiting for all async tasks to be completed
|
||||
AsyncUtil.awaitLatchAndIgnoreInterrupt(completionLatch, 300L, TimeUnit.SECONDS);
|
||||
|
||||
|
||||
// Now, create the bundle response in original order
|
||||
Object nextResponseEntry;
|
||||
for (int i = 0; i < requestEntriesSize; i++) {
|
||||
|
||||
for (int i=0; i<requestEntriesSize; i++ ) {
|
||||
|
||||
nextResponseEntry = responseMap.get(i);
|
||||
if (nextResponseEntry instanceof BaseServerResponseExceptionHolder) {
|
||||
BaseServerResponseExceptionHolder caughtEx = (BaseServerResponseExceptionHolder) nextResponseEntry;
|
||||
BaseServerResponseExceptionHolder caughtEx = (BaseServerResponseExceptionHolder)nextResponseEntry;
|
||||
if (caughtEx.getException() != null) {
|
||||
IBase nextEntry = myVersionAdapter.addEntry(response);
|
||||
populateEntryWithOperationOutcome(caughtEx.getException(), nextEntry);
|
||||
myVersionAdapter.setResponseStatus(nextEntry, toStatusString(caughtEx.getException().getStatusCode()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
myVersionAdapter.addEntry(response, (IBase) nextResponseEntry);
|
||||
myVersionAdapter.addEntry(response, (IBase)nextResponseEntry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
long delay = System.currentTimeMillis() - start;
|
||||
ourLog.info("Batch completed in {}ms", delay);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user