From 57bcc9251208ed2b126ac12308465ec1f9c830f0 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Fri, 31 Dec 2021 00:58:47 +0100 Subject: [PATCH] Fix statistics --- pom.xml | 2 ++ .../database/disk/LLLocalLuceneIndex.java | 20 +++++++++++++------ .../disk/OptimisticRocksDBColumn.java | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index c01dcc5..fb4ded9 100644 --- a/pom.xml +++ b/pom.xml @@ -501,6 +501,8 @@ false false true + true + true diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java index 3b11c2f..32fa3a8 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java @@ -51,6 +51,7 @@ import java.util.concurrent.Phaser; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantLock; +import org.apache.commons.lang3.time.StopWatch; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper; @@ -60,6 +61,7 @@ import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy; import org.apache.lucene.index.MergeScheduler; import org.apache.lucene.index.SerialMergeScheduler; +import org.apache.lucene.index.SimpleMergedSegmentWarmer; import org.apache.lucene.index.SnapshotDeletionPolicy; import org.apache.lucene.index.TieredMergePolicy; import org.apache.lucene.misc.store.DirectIODirectory; @@ -222,6 +224,7 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { indexWriterConfig.setCommitOnClose(true); var mergePolicy = new TieredMergePolicy(); indexWriterConfig.setMergePolicy(mergePolicy); + indexWriterConfig.setMergedSegmentWarmer(new SimpleMergedSegmentWarmer(null)); int writerSchedulerMaxThreadCount; MergeScheduler mergeScheduler; if (lowMemory) { @@ -334,16 +337,21 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { @Override public Mono addDocuments(Flux> documents) { - return documents.collectList().flatMap(documentsList -> this.runSafe(() -> docIndexingTime.recordCallable(() -> { - double count = documentsList.size(); - startedDocIndexings.increment(count); + return documents.collectList().flatMap(documentsList -> this.runSafe(() -> { + var count = documentsList.size(); + StopWatch stopWatch = StopWatch.createStarted(); try { - indexWriter.addDocuments(LLUtils.toDocumentsFromEntries(documentsList)); + startedDocIndexings.increment(count); + try { + indexWriter.addDocuments(LLUtils.toDocumentsFromEntries(documentsList)); + } finally { + endeddDocIndexings.increment(count); + } } finally { - endeddDocIndexings.increment(count); + docIndexingTime.record(stopWatch.getTime(TimeUnit.MILLISECONDS) / Math.max(count, 1), TimeUnit.MILLISECONDS); } return null; - }))).transform(this::ensureOpen); + })).transform(this::ensureOpen); } diff --git a/src/main/java/it/cavallium/dbengine/database/disk/OptimisticRocksDBColumn.java b/src/main/java/it/cavallium/dbengine/database/disk/OptimisticRocksDBColumn.java index 5291a9d..a73ba65 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/OptimisticRocksDBColumn.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/OptimisticRocksDBColumn.java @@ -96,6 +96,7 @@ public final class OptimisticRocksDBColumn extends AbstractRocksDBColumn