Skip to content

Commit

Permalink
Disable gc for LMDB store and use correct uptime of JVM.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenwenzel committed May 22, 2024
1 parent cc7383f commit 1c13bb8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class LmdbSailStore implements SailStore {
private volatile boolean nextTransactionAsync;

boolean enableMultiThreading = true;
boolean enableGc = true;

private PersistentSetFactory<Long> setFactory;
private PersistentSet<Long> unusedIds, nextUnusedIds;
Expand Down Expand Up @@ -760,9 +761,11 @@ private long removeStatements(long subj, long pred, long obj, boolean explicit,
for (long contextId : contexts) {
tripleStore.removeTriplesByContext(subj, pred, obj, contextId, explicit, quad -> {
removeCount[0]++;
for (long id : quad) {
if (id != 0L) {
unusedIds.add(id);
if (enableGc) {
for (long id : quad) {
if (id != 0L) {
unusedIds.add(id);
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ protected LmdbSailStore createSailStore(File dataDir) throws IOException, SailEx
LmdbStoreConfig overflowConfig = new LmdbStoreConfig();
LmdbSailStore store = new LmdbSailStore(dataDir, overflowConfig);
store.enableMultiThreading = false;
store.enableGc = false;
// does not need to isolate transactions and therefore can optimize autogrow and others
store.setTransactionIsolation(false);
return store;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.ObjectOutputStream;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.nio.file.Files;
import java.util.Collection;
import java.util.HashSet;
Expand Down Expand Up @@ -88,11 +89,13 @@ abstract class MemoryOverflowModel extends AbstractModel implements AutoCloseabl
private static volatile List<GcInfo> gcInfos = new CopyOnWriteArrayList<>();
static {
List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
for (GarbageCollectorMXBean gcBean : gcBeans) {
NotificationEmitter emitter = (NotificationEmitter) gcBean;
emitter.addNotificationListener((notification, o) -> {
long uptimeInMillis = runtimeMXBean.getUptime();
while (! gcInfos.isEmpty()) {
if (System.currentTimeMillis() - gcInfos.get(0).getEndTime() > 5000) {
if (uptimeInMillis - gcInfos.get(0).getEndTime() > 5000) {
gcSum -= gcInfos.remove(0).getDuration();
} else {
break;
Expand All @@ -104,8 +107,8 @@ abstract class MemoryOverflowModel extends AbstractModel implements AutoCloseabl
GcInfo gcInfo = gcNotificationInfo.getGcInfo();
gcInfos.add(gcInfo);
gcSum += gcInfo.getDuration();
System.out.println("gcSum: " + gcSum);
if (gcSum > 1000 || gcInfos.size() > 4) {
System.out.println("high gc load: sum=" + gcSum + " count=" + gcInfos.size());
highGcLoad = true;
lastGcUpdate = System.currentTimeMillis();
} else if (System.currentTimeMillis() - lastGcUpdate > 10000) {
Expand Down

0 comments on commit 1c13bb8

Please sign in to comment.