Skip to content

Commit 376fdeb

Browse files
committed
GH-5442 Further optimize multi-threading performance and reduce copy operations.
1 parent 18f1bef commit 376fdeb

File tree

2 files changed

+150
-110
lines changed

2 files changed

+150
-110
lines changed

core/sail/lmdb/src/main/java/org/eclipse/rdf4j/sail/lmdb/LmdbSailStore.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void rollback() throws SailException {
216216
if (tripleStoreException != null) {
217217
throw wrapTripleStoreException();
218218
} else {
219-
Thread.yield();
219+
Thread.onSpinWait();
220220
}
221221
}
222222
} else {
@@ -478,7 +478,7 @@ public void flush() throws SailException {
478478
if (tripleStoreException != null) {
479479
throw wrapTripleStoreException();
480480
} else {
481-
Thread.yield();
481+
Thread.onSpinWait();
482482
}
483483
}
484484
}
@@ -491,7 +491,7 @@ public void flush() throws SailException {
491491
if (tripleStoreException != null) {
492492
throw wrapTripleStoreException();
493493
} else {
494-
Thread.yield();
494+
Thread.onSpinWait();
495495
}
496496
}
497497
}
@@ -676,30 +676,30 @@ private void startTransaction(boolean preferThreading) throws SailException {
676676
} else if (Thread.interrupted()) {
677677
throw new InterruptedException();
678678
} else {
679-
Thread.yield();
679+
Thread.onSpinWait();
680680
}
681681
}
682682
}
683683

684-
// keep thread running for at least 2ms to lock-free wait for the next
684+
// keep thread running for a short while to lock-free wait for the next
685685
// transaction
686686
long start = 0;
687687
while (running.get() && !nextTransactionAsync) {
688688
if (start == 0) {
689689
// System.currentTimeMillis() is expensive, so only call it when we
690690
// are sure we need to wait
691-
start = System.currentTimeMillis();
691+
start = System.nanoTime();
692692
}
693693

694-
if (System.currentTimeMillis() - start > 2) {
694+
if (System.nanoTime() - start > 100000) {
695695
synchronized (storeTxnStarted) {
696696
if (!nextTransactionAsync) {
697697
running.set(false);
698698
return;
699699
}
700700
}
701701
} else {
702-
Thread.yield();
702+
Thread.onSpinWait();
703703
}
704704
}
705705
}
@@ -846,15 +846,15 @@ public void execute() throws Exception {
846846
if (tripleStoreException != null) {
847847
throw wrapTripleStoreException();
848848
} else {
849-
Thread.yield();
849+
Thread.onSpinWait();
850850
}
851851
}
852852

853853
while (!removeOp.finished) {
854854
if (tripleStoreException != null) {
855855
throw wrapTripleStoreException();
856856
} else {
857-
Thread.yield();
857+
Thread.onSpinWait();
858858
}
859859
}
860860
return removeCount[0];
@@ -932,7 +932,7 @@ public CloseableIteration<? extends Statement> getStatements(Resource subj, IRI
932932
try {
933933
logger.warn("Failed to get statements, retrying", e);
934934
// try once more before giving up
935-
Thread.yield();
935+
Thread.onSpinWait();
936936
return createStatementIterator(txn, subj, pred, obj, explicit, contexts);
937937
} catch (IOException e2) {
938938
throw new SailException("Unable to get statements", e);

0 commit comments

Comments
 (0)