From 8c530c347729533973a39708bef0d4b09e57fc21 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Thu, 29 Jun 2023 09:41:28 +0200 Subject: [PATCH] Second try on reading data from memory. --- .../java/biz/nellemann/memstress/Application.java | 8 -------- .../java/biz/nellemann/memstress/MyDatabase.java | 14 +++++++++----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/java/biz/nellemann/memstress/Application.java b/src/main/java/biz/nellemann/memstress/Application.java index 5c87900..5b708a0 100644 --- a/src/main/java/biz/nellemann/memstress/Application.java +++ b/src/main/java/biz/nellemann/memstress/Application.java @@ -3,8 +3,6 @@ package biz.nellemann.memstress; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import picocli.CommandLine; - -import java.util.Scanner; import java.util.concurrent.Callable; @CommandLine.Command(name = "memstress", mixinStandardHelpOptions = true, versionProvider = VersionProvider.class, description = "Memory performance measurement tool.") @@ -29,12 +27,6 @@ public class Application implements Callable { MyDatabase database = new MyDatabase(maxTables, maxRowsPerTable, maxDataPerRow); database.write("testDb"); database.read("testDb"); - - Scanner scanner = new Scanner(System.in); - System.out.println("Press ENTER to stop"); - String s= scanner.nextLine(); - scanner.close(); - database.destroy("testDb"); return 0; diff --git a/src/main/java/biz/nellemann/memstress/MyDatabase.java b/src/main/java/biz/nellemann/memstress/MyDatabase.java index ee23892..282d867 100644 --- a/src/main/java/biz/nellemann/memstress/MyDatabase.java +++ b/src/main/java/biz/nellemann/memstress/MyDatabase.java @@ -56,7 +56,7 @@ public class MyDatabase { for (int t = 1; t <= maxTables; t++) { String tableName = String.format("table_%d", t); - log.info("Creating table \"{}\"", tableName); + log.debug("Creating table \"{}\"", tableName); Table table = database.createTable(tableName); @@ -74,7 +74,7 @@ public class MyDatabase { } Instant instant2 = Instant.now(); - log.info("Done writing {} to \"{}\" in {}", bytesWritten, dbName, Duration.between(instant1, instant2)); + log.info("Done writing {}b to \"{}\" in {}", bytesWritten, dbName, Duration.between(instant1, instant2)); } @@ -87,13 +87,17 @@ public class MyDatabase { table.getRows().forEach((idx, row) -> { HashMap values = row.getColumnValuesMap(); values.forEach((str, byteBuffer) -> { - byte[] array = byteBuffer.array(); - bytesRead.addAndGet(array.length); + byteBuffer.rewind(); + while (byteBuffer.hasRemaining()) { + byte[] tmp = new byte[BYTE_SIZE_1MB]; + byteBuffer.get(tmp); + bytesRead.addAndGet(tmp.length); + } }); }); } Instant instant2 = Instant.now(); - log.info("Done reading {} from \"{}\" in {}", bytesRead.get(), dbName, Duration.between(instant1, instant2)); + log.info("Done reading {}b from \"{}\" in {}", bytesRead.get(), dbName, Duration.between(instant1, instant2)); }