Skip to content

Commit 1c13bb8

Browse files
committed
Disable gc for LMDB store and use correct uptime of JVM.
1 parent cc7383f commit 1c13bb8

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class LmdbSailStore implements SailStore {
7373
private volatile boolean nextTransactionAsync;
7474

7575
boolean enableMultiThreading = true;
76+
boolean enableGc = true;
7677

7778
private PersistentSetFactory<Long> setFactory;
7879
private PersistentSet<Long> unusedIds, nextUnusedIds;
@@ -760,9 +761,11 @@ private long removeStatements(long subj, long pred, long obj, boolean explicit,
760761
for (long contextId : contexts) {
761762
tripleStore.removeTriplesByContext(subj, pred, obj, contextId, explicit, quad -> {
762763
removeCount[0]++;
763-
for (long id : quad) {
764-
if (id != 0L) {
765-
unusedIds.add(id);
764+
if (enableGc) {
765+
for (long id : quad) {
766+
if (id != 0L) {
767+
unusedIds.add(id);
768+
}
766769
}
767770
}
768771
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ protected LmdbSailStore createSailStore(File dataDir) throws IOException, SailEx
258258
LmdbStoreConfig overflowConfig = new LmdbStoreConfig();
259259
LmdbSailStore store = new LmdbSailStore(dataDir, overflowConfig);
260260
store.enableMultiThreading = false;
261+
store.enableGc = false;
261262
// does not need to isolate transactions and therefore can optimize autogrow and others
262263
store.setTransactionIsolation(false);
263264
return store;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.io.ObjectOutputStream;
1818
import java.lang.management.GarbageCollectorMXBean;
1919
import java.lang.management.ManagementFactory;
20+
import java.lang.management.RuntimeMXBean;
2021
import java.nio.file.Files;
2122
import java.util.Collection;
2223
import java.util.HashSet;
@@ -88,11 +89,13 @@ abstract class MemoryOverflowModel extends AbstractModel implements AutoCloseabl
8889
private static volatile List<GcInfo> gcInfos = new CopyOnWriteArrayList<>();
8990
static {
9091
List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
92+
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
9193
for (GarbageCollectorMXBean gcBean : gcBeans) {
9294
NotificationEmitter emitter = (NotificationEmitter) gcBean;
9395
emitter.addNotificationListener((notification, o) -> {
96+
long uptimeInMillis = runtimeMXBean.getUptime();
9497
while (! gcInfos.isEmpty()) {
95-
if (System.currentTimeMillis() - gcInfos.get(0).getEndTime() > 5000) {
98+
if (uptimeInMillis - gcInfos.get(0).getEndTime() > 5000) {
9699
gcSum -= gcInfos.remove(0).getDuration();
97100
} else {
98101
break;
@@ -104,8 +107,8 @@ abstract class MemoryOverflowModel extends AbstractModel implements AutoCloseabl
104107
GcInfo gcInfo = gcNotificationInfo.getGcInfo();
105108
gcInfos.add(gcInfo);
106109
gcSum += gcInfo.getDuration();
107-
System.out.println("gcSum: " + gcSum);
108110
if (gcSum > 1000 || gcInfos.size() > 4) {
111+
System.out.println("high gc load: sum=" + gcSum + " count=" + gcInfos.size());
109112
highGcLoad = true;
110113
lastGcUpdate = System.currentTimeMillis();
111114
} else if (System.currentTimeMillis() - lastGcUpdate > 10000) {

0 commit comments

Comments
 (0)