count disk reads
This commit is contained in:
@@ -53,6 +53,7 @@ public class DiskStorage implements AutoCloseable {
|
|||||||
try {
|
try {
|
||||||
LOGGER.trace("read block={} file={}", blockOffset, relativeDatabaseFileForLogging);
|
LOGGER.trace("read block={} file={}", blockOffset, relativeDatabaseFileForLogging);
|
||||||
|
|
||||||
|
DiskStoreStats.incrementDiskRead();
|
||||||
final var byteBuffer = fileChannel.map(MapMode.READ_WRITE, blockOffset, blockSize);
|
final var byteBuffer = fileChannel.map(MapMode.READ_WRITE, blockOffset, blockSize);
|
||||||
|
|
||||||
return new DiskBlock(blockOffset, byteBuffer);
|
return new DiskBlock(blockOffset, byteBuffer);
|
||||||
@@ -227,6 +228,7 @@ public class DiskStorage implements AutoCloseable {
|
|||||||
|
|
||||||
private FreeListNode readFreeListNode(final long freeListNodePosition) throws IOException {
|
private FreeListNode readFreeListNode(final long freeListNodePosition) throws IOException {
|
||||||
final var freeListNode = ByteBuffer.allocate(FREE_LIST_NODE_SIZE);
|
final var freeListNode = ByteBuffer.allocate(FREE_LIST_NODE_SIZE);
|
||||||
|
DiskStoreStats.incrementDiskRead();
|
||||||
fileChannel.read(freeListNode, freeListNodePosition);
|
fileChannel.read(freeListNode, freeListNodePosition);
|
||||||
final long offset = freeListNodePosition;
|
final long offset = freeListNodePosition;
|
||||||
final long next = freeListNode.getLong(FREE_LIST_NEXT_POINTER);
|
final long next = freeListNode.getLong(FREE_LIST_NEXT_POINTER);
|
||||||
@@ -250,6 +252,7 @@ public class DiskStorage implements AutoCloseable {
|
|||||||
|
|
||||||
private long readFreeListRootNodePosition() throws IOException {
|
private long readFreeListRootNodePosition() throws IOException {
|
||||||
final var freeListFirstBlock = ByteBuffer.allocate(8);
|
final var freeListFirstBlock = ByteBuffer.allocate(8);
|
||||||
|
DiskStoreStats.incrementDiskRead();
|
||||||
fileChannel.read(freeListFirstBlock, FREE_LIST_ROOT_OFFSET);
|
fileChannel.read(freeListFirstBlock, FREE_LIST_ROOT_OFFSET);
|
||||||
return freeListFirstBlock.getLong(0);
|
return freeListFirstBlock.getLong(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,7 @@ import org.lucares.pdb.datastore.lang.Expression;
|
|||||||
import org.lucares.pdb.datastore.lang.ExpressionToDocIdVisitor;
|
import org.lucares.pdb.datastore.lang.ExpressionToDocIdVisitor;
|
||||||
import org.lucares.pdb.datastore.lang.NewProposerParser;
|
import org.lucares.pdb.datastore.lang.NewProposerParser;
|
||||||
import org.lucares.pdb.datastore.lang.QueryLanguageParser;
|
import org.lucares.pdb.datastore.lang.QueryLanguageParser;
|
||||||
|
import org.lucares.pdb.diskstorage.DiskStoreStats;
|
||||||
import org.lucares.pdb.map.PersistentMap;
|
import org.lucares.pdb.map.PersistentMap;
|
||||||
import org.lucares.utils.Preconditions;
|
import org.lucares.utils.Preconditions;
|
||||||
import org.lucares.utils.cache.HotEntryCache;
|
import org.lucares.utils.cache.HotEntryCache;
|
||||||
@@ -235,11 +236,16 @@ public class DataStore implements AutoCloseable {
|
|||||||
|
|
||||||
public List<Doc> search(final Query query) {
|
public List<Doc> search(final Query query) {
|
||||||
try {
|
try {
|
||||||
|
DiskStoreStats.resetDiskRead();
|
||||||
final List<Doc> result = new ArrayList<>();
|
final List<Doc> result = new ArrayList<>();
|
||||||
|
|
||||||
final PartitionLongList docIdsList = executeQuery(query);
|
final PartitionLongList docIdsList = executeQuery(query);
|
||||||
LOGGER.trace("query {} found {} docs", query, docIdsList.size());
|
LOGGER.trace("query {} found {} docs", query, docIdsList.size());
|
||||||
|
|
||||||
|
DiskStoreStats.incrementDiskRead();
|
||||||
|
LOGGER.info("Disk reads - search {}", DiskStoreStats.getAndResetDiskRead());
|
||||||
final List<Doc> docs = mapDocIdsToDocs(docIdsList);
|
final List<Doc> docs = mapDocIdsToDocs(docIdsList);
|
||||||
|
LOGGER.info("Disk reads - mappedToDocIds {}", DiskStoreStats.getAndResetDiskRead());
|
||||||
result.addAll(docs);
|
result.addAll(docs);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user