diff --git a/src/jmh/java/com/tomfran/lsm/tree/LSMTreeAddBenchmark.java b/src/jmh/java/com/tomfran/lsm/tree/LSMTreeAddBenchmark.java index 3b94187..f2d876e 100644 --- a/src/jmh/java/com/tomfran/lsm/tree/LSMTreeAddBenchmark.java +++ b/src/jmh/java/com/tomfran/lsm/tree/LSMTreeAddBenchmark.java @@ -4,7 +4,6 @@ import com.tomfran.lsm.utils.BenchmarkUtils; import org.openjdk.jmh.annotations.*; -import java.io.IOException; import java.nio.file.Path; import java.util.concurrent.TimeUnit; @@ -12,7 +11,7 @@ @State(Scope.Benchmark) public class LSMTreeAddBenchmark { - static final Path DIR = Path.of("tree_benchmark"); + static final Path DIR = Path.of("tree_add_benchmark"); static final int NUM_ITEMS = 1000000; static final int MEMTABLE_SIZE = 1 << 18; static final int LEVEL_SIZE = 5; @@ -22,16 +21,14 @@ public class LSMTreeAddBenchmark { ByteArrayPair[] items; @Setup - public void setup() throws IOException { + public void setup() { tree = BenchmarkUtils.initTree(DIR, MEMTABLE_SIZE, LEVEL_SIZE); items = BenchmarkUtils.fillItems(NUM_ITEMS); } @TearDown - public void teardown() throws InterruptedException { - tree.stop(); - Thread.sleep(5000); - BenchmarkUtils.deleteDir(DIR); + public void teardown() { + BenchmarkUtils.stopTreeAndCleanDisk(tree, DIR); } @Benchmark diff --git a/src/jmh/java/com/tomfran/lsm/tree/LSMTreeGetBenchmark.java b/src/jmh/java/com/tomfran/lsm/tree/LSMTreeGetBenchmark.java index 3443f10..025ac6a 100644 --- a/src/jmh/java/com/tomfran/lsm/tree/LSMTreeGetBenchmark.java +++ b/src/jmh/java/com/tomfran/lsm/tree/LSMTreeGetBenchmark.java @@ -5,7 +5,6 @@ import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; -import java.io.IOException; import java.nio.file.Path; import java.util.concurrent.TimeUnit; @@ -15,7 +14,7 @@ @State(Scope.Benchmark) public class LSMTreeGetBenchmark { - static final Path DIR = Path.of("tree_benchmark"); + static final Path DIR = Path.of("tree_get_benchmark"); static final int NUM_ITEMS = 1000000; static final int MEMTABLE_SIZE = 1 << 18; static final int LEVEL_SIZE = 5; @@ -25,7 +24,7 @@ public class LSMTreeGetBenchmark { ByteArrayPair[] items; @Setup - public void setup() throws IOException { + public void setup() { tree = BenchmarkUtils.initTree(DIR, MEMTABLE_SIZE, LEVEL_SIZE); items = BenchmarkUtils.fillItems(NUM_ITEMS); for (var i : items) @@ -35,10 +34,8 @@ public void setup() throws IOException { } @TearDown - public void teardown() throws InterruptedException { - tree.stop(); - Thread.sleep(5000); - BenchmarkUtils.deleteDir(DIR); + public void teardown() { + BenchmarkUtils.stopTreeAndCleanDisk(tree, DIR); } @Benchmark diff --git a/src/jmh/java/com/tomfran/lsm/utils/BenchmarkUtils.java b/src/jmh/java/com/tomfran/lsm/utils/BenchmarkUtils.java index 7806492..7ff04b9 100644 --- a/src/jmh/java/com/tomfran/lsm/utils/BenchmarkUtils.java +++ b/src/jmh/java/com/tomfran/lsm/utils/BenchmarkUtils.java @@ -13,14 +13,22 @@ public class BenchmarkUtils { public static LSMTree initTree(Path dir, int memSize, int levelSize) { - // setup directory if (Files.exists(dir)) deleteDir(dir); - // setup tree return new LSMTree(memSize, levelSize, dir.toString()); } + public static void stopTreeAndCleanDisk(LSMTree tree, Path dir) { + try { + tree.stop(); + Thread.sleep(5000); + } catch (Exception ignored) { + } + + deleteDir(dir); + } + public static ByteArrayPair[] fillItems(int n) { ByteArrayPair[] items = new ByteArrayPair[n]; for (int i = 0; i < n; i++) @@ -39,8 +47,11 @@ public static void shuffleItems(ByteArrayPair[] v) { } public static void deleteDir(Path dir) { - try (var f = Files.walk(dir)) { - f.map(Path::toFile).forEach(File::delete); + try { + try (var f = Files.walk(dir)) { + f.map(Path::toFile).forEach(File::delete); + } + Files.delete(dir); } catch (Exception ignored) { } }