count disk reads

This commit is contained in:
2020-09-20 19:51:47 +02:00
parent 69f12aba98
commit 6bb6cdaea7
3 changed files with 33 additions and 0 deletions

View File

@@ -53,6 +53,7 @@ public class DiskStorage implements AutoCloseable {
try {
LOGGER.trace("read block={} file={}", blockOffset, relativeDatabaseFileForLogging);
DiskStoreStats.incrementDiskRead();
final var byteBuffer = fileChannel.map(MapMode.READ_WRITE, blockOffset, blockSize);
return new DiskBlock(blockOffset, byteBuffer);
@@ -227,6 +228,7 @@ public class DiskStorage implements AutoCloseable {
private FreeListNode readFreeListNode(final long freeListNodePosition) throws IOException {
final var freeListNode = ByteBuffer.allocate(FREE_LIST_NODE_SIZE);
DiskStoreStats.incrementDiskRead();
fileChannel.read(freeListNode, freeListNodePosition);
final long offset = freeListNodePosition;
final long next = freeListNode.getLong(FREE_LIST_NEXT_POINTER);
@@ -250,6 +252,7 @@ public class DiskStorage implements AutoCloseable {
private long readFreeListRootNodePosition() throws IOException {
final var freeListFirstBlock = ByteBuffer.allocate(8);
DiskStoreStats.incrementDiskRead();
fileChannel.read(freeListFirstBlock, FREE_LIST_ROOT_OFFSET);
return freeListFirstBlock.getLong(0);
}

View File

@@ -0,0 +1,24 @@
package org.lucares.pdb.diskstorage;
import java.util.concurrent.atomic.AtomicLong;
public class DiskStoreStats {
private static final AtomicLong diskRead = new AtomicLong(0);
public static void incrementDiskRead() {
diskRead.incrementAndGet();
}
public static void resetDiskRead() {
diskRead.set(0);
}
public static long getDiskRead() {
return diskRead.get();
}
public static long getAndResetDiskRead() {
return diskRead.getAndSet(0);
}
}

View File

@@ -32,6 +32,7 @@ import org.lucares.pdb.datastore.lang.Expression;
import org.lucares.pdb.datastore.lang.ExpressionToDocIdVisitor;
import org.lucares.pdb.datastore.lang.NewProposerParser;
import org.lucares.pdb.datastore.lang.QueryLanguageParser;
import org.lucares.pdb.diskstorage.DiskStoreStats;
import org.lucares.pdb.map.PersistentMap;
import org.lucares.utils.Preconditions;
import org.lucares.utils.cache.HotEntryCache;
@@ -235,11 +236,16 @@ public class DataStore implements AutoCloseable {
public List<Doc> search(final Query query) {
try {
DiskStoreStats.resetDiskRead();
final List<Doc> result = new ArrayList<>();
final PartitionLongList docIdsList = executeQuery(query);
LOGGER.trace("query {} found {} docs", query, docIdsList.size());
DiskStoreStats.incrementDiskRead();
LOGGER.info("Disk reads - search {}", DiskStoreStats.getAndResetDiskRead());
final List<Doc> docs = mapDocIdsToDocs(docIdsList);
LOGGER.info("Disk reads - mappedToDocIds {}", DiskStoreStats.getAndResetDiskRead());
result.addAll(docs);
return result;