From e1d3395fa3518c6c85c9c4173ddb28796bbaed6d Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Thu, 29 Jun 2023 11:05:45 +0200 Subject: [PATCH] Average times and multiple test iterations. --- README.md | 35 +++---------------- .../biz/nellemann/memstress/Application.java | 21 ++++++++--- .../{MyDatabase.java => MemDatabase.java} | 19 ++++++---- 3 files changed, 33 insertions(+), 42 deletions(-) rename src/main/java/biz/nellemann/memstress/{MyDatabase.java => MemDatabase.java} (84%) diff --git a/README.md b/README.md index 9a7018e..adf38d6 100644 --- a/README.md +++ b/README.md @@ -3,39 +3,12 @@ ## Examples +Test with 8GB memory: ```shell -java -Xms128g -Xmx128g -XX:+UseLargePages -XX:+AlwaysPreTouch \ - -XX:-UseParallelGC -XX:MaxGCPauseMillis=500 -Xgcthreads3 \ - -jar memstress-0.0.1-all.jar -t 96 +java -Xms10g -Xmx10g -XX:+AlwaysPreTouch -jar memstress-0.0.1-all.jar -t 8 ``` - +Test with 100GB memory: ```shell -java -Xms144g -Xmx144g -XX:+UseLargePages -XX:+AlwaysPreTouch \ - -XX:-UseParallelGC -XX:MaxGCPauseMillis=500 -Xgcthreads3 \ - -jar memstress-0.0.1-all.jar -t 128 -``` - -```shell -java -Xms160g -Xmx160g -XX:+UseLargePages -XX:+AlwaysPreTouch \ - -XX:-UseParallelGC -XX:MaxGCPauseMillis=500 -Xgcthreads3 \ - -jar memstress-0.0.1-all.jar -t 144 -``` - -```shell -java -Xms192g -Xmx192g -XX:+UseLargePages -XX:+AlwaysPreTouch \ - -XX:-UseParallelGC -XX:MaxGCPauseMillis=500 -Xgcthreads3 \ - -jar memstress-0.0.1-all.jar -t 160 -``` - -```shell -java -Xms240g -Xmx240g -XX:+UseLargePages -XX:+AlwaysPreTouch \ - -XX:-UseParallelGC -XX:MaxGCPauseMillis=500 -Xgcthreads3 \ - -jar memstress-0.0.1-all.jar -t 192 -``` - -```shell -java -Xms256g -Xmx256g -XX:+UseLargePages -XX:+AlwaysPreTouch \ - -XX:-UseParallelGC -XX:MaxGCPauseMillis=500 -Xgcthreads3 \ - -jar memstress-0.0.1-all.jar -t 240 +java -Xms128g -Xmx128g -XX:+AlwaysPreTouch -jar memstress-0.0.1-all.jar -t 100 ``` diff --git a/src/main/java/biz/nellemann/memstress/Application.java b/src/main/java/biz/nellemann/memstress/Application.java index 5b708a0..f03bb6f 100644 --- a/src/main/java/biz/nellemann/memstress/Application.java +++ b/src/main/java/biz/nellemann/memstress/Application.java @@ -3,6 +3,8 @@ package biz.nellemann.memstress; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import picocli.CommandLine; + +import java.time.Duration; import java.util.concurrent.Callable; @CommandLine.Command(name = "memstress", mixinStandardHelpOptions = true, versionProvider = VersionProvider.class, description = "Memory performance measurement tool.") @@ -20,14 +22,25 @@ public class Application implements Callable { @CommandLine.Option(names = { "-d", "--data" }, paramLabel = "NUM", description = "Create this much data (MB) pr. row [default: ${DEFAULT-VALUE}]") int maxDataPerRow = 100; + @CommandLine.Option(names = { "-i", "--iterations" }, paramLabel = "NUM", description = "Iterate test his many times [default: ${DEFAULT-VALUE}]") + int iterations = 3; @Override public Integer call() throws Exception { - MyDatabase database = new MyDatabase(maxTables, maxRowsPerTable, maxDataPerRow); - database.write("testDb"); - database.read("testDb"); - database.destroy("testDb"); + long writeTimeMillis = 0; + long readTimeMillis = 0; + + for(int i = 1; i <= iterations; i++) { + log.info("Starting test {} of {}", i, iterations); + MemDatabase database = new MemDatabase(maxTables, maxRowsPerTable, maxDataPerRow); + writeTimeMillis += database.write("testDb"); + readTimeMillis += database.read("testDb"); + database.destroy("testDb"); + } + + log.info("Average writing time: {}", Duration.ofMillis(writeTimeMillis / iterations)); + log.info("Average reading time: {}", Duration.ofMillis(readTimeMillis / iterations)); return 0; } diff --git a/src/main/java/biz/nellemann/memstress/MyDatabase.java b/src/main/java/biz/nellemann/memstress/MemDatabase.java similarity index 84% rename from src/main/java/biz/nellemann/memstress/MyDatabase.java rename to src/main/java/biz/nellemann/memstress/MemDatabase.java index 282d867..07c581f 100644 --- a/src/main/java/biz/nellemann/memstress/MyDatabase.java +++ b/src/main/java/biz/nellemann/memstress/MemDatabase.java @@ -14,9 +14,9 @@ import java.util.Arrays; import java.util.HashMap; import java.util.concurrent.atomic.AtomicLong; -public class MyDatabase { +public class MemDatabase { - final Logger log = LoggerFactory.getLogger(MyDatabase.class); + final Logger log = LoggerFactory.getLogger(MemDatabase.class); private final int BYTE_SIZE_1MB = 1_000_000; private final int BYTE_SIZE_1GB = 1_000_000_000; @@ -35,7 +35,7 @@ public class MyDatabase { private char[] baseCar; private byte[] byteBase; - public MyDatabase(int tables, int rows, int size) { + public MemDatabase(int tables, int rows, int size) { this.maxTables = tables; this.maxRowsPerTable = rows; this.maxDataPerRow = size; @@ -48,7 +48,7 @@ public class MyDatabase { } - public void write(String dbName) { + public long write(String dbName) { Instant instant1 = Instant.now(); Database database = databaseManager.createDatabase(dbName); @@ -74,11 +74,14 @@ public class MyDatabase { } Instant instant2 = Instant.now(); - log.info("Done writing {}b to \"{}\" in {}", bytesWritten, dbName, Duration.between(instant1, instant2)); + Duration duration = Duration.between(instant1, instant2); + log.info("Done writing {} bytes -> \"{}\" in {}", bytesWritten, dbName, duration); + + return duration.toMillis(); } - public void read(String dbName) { + public long read(String dbName) { Instant instant1 = Instant.now(); Database database = databaseManager.getDatabase(dbName); @@ -97,8 +100,10 @@ public class MyDatabase { }); } Instant instant2 = Instant.now(); - log.info("Done reading {}b from \"{}\" in {}", bytesRead.get(), dbName, Duration.between(instant1, instant2)); + Duration duration = Duration.between(instant1, instant2); + log.info("Done reading {} bytes <- \"{}\" in {}", bytesRead.get(), dbName, duration); + return duration.toMillis(); }