From aad4fc33d5c4b830cebee45a4d7614668688c56c Mon Sep 17 00:00:00 2001 From: Benjamin Prud'homme Date: Sun, 4 Aug 2024 18:33:35 -0400 Subject: [PATCH 1/8] JMH benchmarks (fibers) --- docker/Linux-JDK21/Dockerfile | 1 + .../java/edu/illinois/library/cantaloupe/async/ThreadPool.java | 1 + 2 files changed, 2 insertions(+) diff --git a/docker/Linux-JDK21/Dockerfile b/docker/Linux-JDK21/Dockerfile index 2994e88d4..90dbdabc7 100644 --- a/docker/Linux-JDK21/Dockerfile +++ b/docker/Linux-JDK21/Dockerfile @@ -68,3 +68,4 @@ COPY --chown=cantaloupe docker/Linux-JDK11/image_files/test.properties test.prop COPY --chown=cantaloupe ./src src ENTRYPOINT mvn --batch-mode test -Pfreedeps +ENTRYPOINT mvn --batch-mode test -Pbenchmark diff --git a/src/main/java/edu/illinois/library/cantaloupe/async/ThreadPool.java b/src/main/java/edu/illinois/library/cantaloupe/async/ThreadPool.java index e9a29a7e0..40849601a 100644 --- a/src/main/java/edu/illinois/library/cantaloupe/async/ThreadPool.java +++ b/src/main/java/edu/illinois/library/cantaloupe/async/ThreadPool.java @@ -31,6 +31,7 @@ private String getThreadID() { abstract String getThreadNamePrefix(); public Thread newThread(Runnable runnable) { + System.out.println("Refactoring in ThreadPool hit"); Thread thread = Thread.ofVirtual().name(getThreadNamePrefix() + "-", Long.parseLong(getThreadID())).unstarted(runnable); return thread; } From 51cf63fedab8a8e164d406c276524cf48cf2992f Mon Sep 17 00:00:00 2001 From: Benjamin Prud'homme Date: Thu, 8 Aug 2024 09:53:53 -0400 Subject: [PATCH 2/8] Add for loops to JMH --- .../processor/FfmpegProcessorPerformance.java | 94 ++++++++++++------- 1 file changed, 58 insertions(+), 36 deletions(-) diff --git a/src/test/java/edu/illinois/library/cantaloupe/perf/processor/FfmpegProcessorPerformance.java b/src/test/java/edu/illinois/library/cantaloupe/perf/processor/FfmpegProcessorPerformance.java index be4a08235..faca690ae 100644 --- a/src/test/java/edu/illinois/library/cantaloupe/perf/processor/FfmpegProcessorPerformance.java +++ b/src/test/java/edu/illinois/library/cantaloupe/perf/processor/FfmpegProcessorPerformance.java @@ -18,6 +18,7 @@ import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.annotations.State; @@ -37,6 +38,9 @@ public class FfmpegProcessorPerformance { private FileProcessor processor; + + @Param({"10", "50", "100", "500", "1000", "5000"}) + private int threads; @Setup public void setUp() throws Exception { @@ -52,62 +56,80 @@ public void tearDown() { @Benchmark public void processWithAVI() throws Exception { - processor.setSourceFormat(Format.get("avi")); - processor.setSourceFile(TestUtil.getImage("avi")); - processor.process( - OperationList.builder().withOperations(new Encode(Format.get("png"))).build(), - Info.builder().withSize(640, 360).build(), - OutputStream.nullOutputStream()); + for (int i=0; i Date: Thu, 8 Aug 2024 21:40:36 -0400 Subject: [PATCH 3/8] Add JMH to tests iterating over threads --- .../cantaloupe/cache/AbstractCacheTest.java | 4 +- .../cantaloupe/cache/FilesystemCacheTest.java | 39 ++++++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/test/java/edu/illinois/library/cantaloupe/cache/AbstractCacheTest.java b/src/test/java/edu/illinois/library/cantaloupe/cache/AbstractCacheTest.java index 8b04f03d6..75f91699d 100644 --- a/src/test/java/edu/illinois/library/cantaloupe/cache/AbstractCacheTest.java +++ b/src/test/java/edu/illinois/library/cantaloupe/cache/AbstractCacheTest.java @@ -189,7 +189,7 @@ void testNewDerivativeImageInputStreamWithNonexistentImage() } @Test - void testNewDerivativeImageInputStreamConcurrently() throws Exception { + void testNewDerivativeImageInputStreamConcurrently(int numThreads) throws Exception { final DerivativeCache instance = newInstance(); final OperationList ops = OperationList.builder() .withIdentifier(new Identifier("cats")) @@ -213,7 +213,7 @@ void testNewDerivativeImageInputStreamConcurrently() throws Exception { } } return null; - }).run(); + }, numThreads).run(); } /* newDerivativeImageOutputStream() */ diff --git a/src/test/java/edu/illinois/library/cantaloupe/cache/FilesystemCacheTest.java b/src/test/java/edu/illinois/library/cantaloupe/cache/FilesystemCacheTest.java index 39e9abffb..496bfb3be 100644 --- a/src/test/java/edu/illinois/library/cantaloupe/cache/FilesystemCacheTest.java +++ b/src/test/java/edu/illinois/library/cantaloupe/cache/FilesystemCacheTest.java @@ -36,6 +36,29 @@ import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assumptions.assumeFalse; +import java.util.concurrent.TimeUnit; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; +import org.openjdk.jmh.annotations.Warmup; +import static edu.illinois.library.cantaloupe.test.PerformanceTestConstants.*; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@Warmup(iterations = WARMUP_ITERATIONS, + time = WARMUP_TIME) +@Measurement(iterations = MEASUREMENT_ITERATIONS, + time = MEASUREMENT_TIME) +@State(Scope.Benchmark) +@Fork(value = 1, jvmArgs = { "-server", "-Xms128M", "-Xmx128M", "-Dcantaloupe.config=memory" }) public class FilesystemCacheTest extends AbstractCacheTest { private Path fixturePath; @@ -43,8 +66,12 @@ public class FilesystemCacheTest extends AbstractCacheTest { private Path sourceImagePath; private Path derivativeImagePath; private FilesystemCache instance; + + @Param({"10", "50", "100", "500", "1000", "5000"}) + private int numThreads; @BeforeEach + @Setup public void setUp() throws Exception { super.setUp(); @@ -57,6 +84,7 @@ public void setUp() throws Exception { } @AfterEach + @TearDown public void tearDown() throws IOException { try { Files.walkFileTree(fixturePath, new DeletingFileVisitor()); @@ -374,7 +402,8 @@ void testGetSourceImageFileWithNonzeroTTL() throws Exception { } @Test - void testGetSourceImageFileConcurrently() throws Exception { + @Benchmark + public void testGetSourceImageFileConcurrently() throws Exception { assumeFalse(SystemUtils.IS_OS_WINDOWS); // TODO: this fails in Windows CI with a flurry of AccessDeniedExceptions final Identifier identifier = new Identifier("monkeys"); @@ -387,14 +416,14 @@ void testGetSourceImageFileConcurrently() throws Exception { }, () -> { instance.getSourceImageFile(identifier); return null; - }).run(); + }, numThreads).run(); } @Test - @Override - void testNewDerivativeImageInputStreamConcurrently() throws Exception { + @Benchmark + public void testNewDerivativeImageInputStreamConcurrently() throws Exception { assumeFalse(SystemUtils.IS_OS_WINDOWS); // TODO: this fails in Windows CI with a flurry of AccessDeniedExceptions - super.testNewDerivativeImageInputStreamConcurrently(); + super.testNewDerivativeImageInputStreamConcurrently(numThreads); } /* newSourceImageOutputStream(Identifier) */ From b1fc6329ce24851687f6d7af5a27a765d69b244a Mon Sep 17 00:00:00 2001 From: Benjamin Prud'homme Date: Fri, 9 Aug 2024 10:33:26 -0400 Subject: [PATCH 4/8] Revert "Add JMH to tests iterating over threads" This reverts commit 72001b2a44487c331e30c10aec83a9f7708cac34. --- .../cantaloupe/cache/AbstractCacheTest.java | 4 +- .../cantaloupe/cache/FilesystemCacheTest.java | 39 +++---------------- 2 files changed, 7 insertions(+), 36 deletions(-) diff --git a/src/test/java/edu/illinois/library/cantaloupe/cache/AbstractCacheTest.java b/src/test/java/edu/illinois/library/cantaloupe/cache/AbstractCacheTest.java index 75f91699d..8b04f03d6 100644 --- a/src/test/java/edu/illinois/library/cantaloupe/cache/AbstractCacheTest.java +++ b/src/test/java/edu/illinois/library/cantaloupe/cache/AbstractCacheTest.java @@ -189,7 +189,7 @@ void testNewDerivativeImageInputStreamWithNonexistentImage() } @Test - void testNewDerivativeImageInputStreamConcurrently(int numThreads) throws Exception { + void testNewDerivativeImageInputStreamConcurrently() throws Exception { final DerivativeCache instance = newInstance(); final OperationList ops = OperationList.builder() .withIdentifier(new Identifier("cats")) @@ -213,7 +213,7 @@ void testNewDerivativeImageInputStreamConcurrently(int numThreads) throws Except } } return null; - }, numThreads).run(); + }).run(); } /* newDerivativeImageOutputStream() */ diff --git a/src/test/java/edu/illinois/library/cantaloupe/cache/FilesystemCacheTest.java b/src/test/java/edu/illinois/library/cantaloupe/cache/FilesystemCacheTest.java index 496bfb3be..39e9abffb 100644 --- a/src/test/java/edu/illinois/library/cantaloupe/cache/FilesystemCacheTest.java +++ b/src/test/java/edu/illinois/library/cantaloupe/cache/FilesystemCacheTest.java @@ -36,29 +36,6 @@ import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assumptions.assumeFalse; -import java.util.concurrent.TimeUnit; -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.BenchmarkMode; -import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Measurement; -import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.annotations.OutputTimeUnit; -import org.openjdk.jmh.annotations.Param; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.TearDown; -import org.openjdk.jmh.annotations.Warmup; -import static edu.illinois.library.cantaloupe.test.PerformanceTestConstants.*; - -@BenchmarkMode(Mode.AverageTime) -@OutputTimeUnit(TimeUnit.MICROSECONDS) -@Warmup(iterations = WARMUP_ITERATIONS, - time = WARMUP_TIME) -@Measurement(iterations = MEASUREMENT_ITERATIONS, - time = MEASUREMENT_TIME) -@State(Scope.Benchmark) -@Fork(value = 1, jvmArgs = { "-server", "-Xms128M", "-Xmx128M", "-Dcantaloupe.config=memory" }) public class FilesystemCacheTest extends AbstractCacheTest { private Path fixturePath; @@ -66,12 +43,8 @@ public class FilesystemCacheTest extends AbstractCacheTest { private Path sourceImagePath; private Path derivativeImagePath; private FilesystemCache instance; - - @Param({"10", "50", "100", "500", "1000", "5000"}) - private int numThreads; @BeforeEach - @Setup public void setUp() throws Exception { super.setUp(); @@ -84,7 +57,6 @@ public void setUp() throws Exception { } @AfterEach - @TearDown public void tearDown() throws IOException { try { Files.walkFileTree(fixturePath, new DeletingFileVisitor()); @@ -402,8 +374,7 @@ void testGetSourceImageFileWithNonzeroTTL() throws Exception { } @Test - @Benchmark - public void testGetSourceImageFileConcurrently() throws Exception { + void testGetSourceImageFileConcurrently() throws Exception { assumeFalse(SystemUtils.IS_OS_WINDOWS); // TODO: this fails in Windows CI with a flurry of AccessDeniedExceptions final Identifier identifier = new Identifier("monkeys"); @@ -416,14 +387,14 @@ public void testGetSourceImageFileConcurrently() throws Exception { }, () -> { instance.getSourceImageFile(identifier); return null; - }, numThreads).run(); + }).run(); } @Test - @Benchmark - public void testNewDerivativeImageInputStreamConcurrently() throws Exception { + @Override + void testNewDerivativeImageInputStreamConcurrently() throws Exception { assumeFalse(SystemUtils.IS_OS_WINDOWS); // TODO: this fails in Windows CI with a flurry of AccessDeniedExceptions - super.testNewDerivativeImageInputStreamConcurrently(numThreads); + super.testNewDerivativeImageInputStreamConcurrently(); } /* newSourceImageOutputStream(Identifier) */ From c0a67f324af723fcbb002524dd3854cb624504a2 Mon Sep 17 00:00:00 2001 From: Benjamin Prud'homme Date: Mon, 12 Aug 2024 17:03:46 -0400 Subject: [PATCH 5/8] Remove print statements --- .../edu/illinois/library/cantaloupe/async/ThreadPool.java | 1 - .../perf/processor/FfmpegProcessorPerformance.java | 6 ------ 2 files changed, 7 deletions(-) diff --git a/src/main/java/edu/illinois/library/cantaloupe/async/ThreadPool.java b/src/main/java/edu/illinois/library/cantaloupe/async/ThreadPool.java index 40849601a..e9a29a7e0 100644 --- a/src/main/java/edu/illinois/library/cantaloupe/async/ThreadPool.java +++ b/src/main/java/edu/illinois/library/cantaloupe/async/ThreadPool.java @@ -31,7 +31,6 @@ private String getThreadID() { abstract String getThreadNamePrefix(); public Thread newThread(Runnable runnable) { - System.out.println("Refactoring in ThreadPool hit"); Thread thread = Thread.ofVirtual().name(getThreadNamePrefix() + "-", Long.parseLong(getThreadID())).unstarted(runnable); return thread; } diff --git a/src/test/java/edu/illinois/library/cantaloupe/perf/processor/FfmpegProcessorPerformance.java b/src/test/java/edu/illinois/library/cantaloupe/perf/processor/FfmpegProcessorPerformance.java index faca690ae..3986434b3 100644 --- a/src/test/java/edu/illinois/library/cantaloupe/perf/processor/FfmpegProcessorPerformance.java +++ b/src/test/java/edu/illinois/library/cantaloupe/perf/processor/FfmpegProcessorPerformance.java @@ -57,7 +57,6 @@ public void tearDown() { @Benchmark public void processWithAVI() throws Exception { for (int i=0; i Date: Wed, 14 Aug 2024 14:35:04 -0400 Subject: [PATCH 6/8] Update Dockerfile --- docker/Linux-JDK21/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/Linux-JDK21/Dockerfile b/docker/Linux-JDK21/Dockerfile index 90dbdabc7..2994e88d4 100644 --- a/docker/Linux-JDK21/Dockerfile +++ b/docker/Linux-JDK21/Dockerfile @@ -68,4 +68,3 @@ COPY --chown=cantaloupe docker/Linux-JDK11/image_files/test.properties test.prop COPY --chown=cantaloupe ./src src ENTRYPOINT mvn --batch-mode test -Pfreedeps -ENTRYPOINT mvn --batch-mode test -Pbenchmark From b50474b0999ca4fdfce2f83e88fef76dba5c4212 Mon Sep 17 00:00:00 2001 From: Benjamin Prud'homme <139664105+bgprudhomme@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:00:12 -0400 Subject: [PATCH 7/8] Update README.md --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b53f62d9..30aba2b8d 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ file available that will spin up all needed dependencies in separate containers, and run the tests in another container. From the project root directory, invoke: - `docker-compose -f docker/{platform}/docker-compose.yml up --build --exit-code-from cantaloupe`. + `docker compose -f docker/{platform}/docker-compose.yml up --build --exit-code-from cantaloupe`. ### Output testing @@ -84,6 +84,13 @@ that enables visual inspection of image output. Performance tests use [JMH](http://openjdk.java.net/projects/code-tools/jmh/). Run them with `mvn clean test -Pbenchmark`. +To compose Docker image and pipe JMH results to output, run: + +``` +docker compose -f docker/Linux-JDK21/docker-compose.yml up --build -d +docker exec -it linux-jdk21-cantaloupe-1 mvn --batch-mode test -Pbenchmark > out.txt +``` + ## Contribute The suggested process for contributing code changes is: From b1bd24f2edf396e5d229d6802651aeda3da08536 Mon Sep 17 00:00:00 2001 From: Benjamin Prud'homme Date: Mon, 19 Aug 2024 12:42:08 -0400 Subject: [PATCH 8/8] Revert "Update README.md" This reverts commit b50474b0999ca4fdfce2f83e88fef76dba5c4212. --- README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index 30aba2b8d..3b53f62d9 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ file available that will spin up all needed dependencies in separate containers, and run the tests in another container. From the project root directory, invoke: - `docker compose -f docker/{platform}/docker-compose.yml up --build --exit-code-from cantaloupe`. + `docker-compose -f docker/{platform}/docker-compose.yml up --build --exit-code-from cantaloupe`. ### Output testing @@ -84,13 +84,6 @@ that enables visual inspection of image output. Performance tests use [JMH](http://openjdk.java.net/projects/code-tools/jmh/). Run them with `mvn clean test -Pbenchmark`. -To compose Docker image and pipe JMH results to output, run: - -``` -docker compose -f docker/Linux-JDK21/docker-compose.yml up --build -d -docker exec -it linux-jdk21-cantaloupe-1 mvn --batch-mode test -Pbenchmark > out.txt -``` - ## Contribute The suggested process for contributing code changes is: