From 6872c45faff0674ae52077a2ce10b142a03285e8 Mon Sep 17 00:00:00 2001 From: Benjamin Prud'homme Date: Mon, 19 Feb 2024 22:14:09 -0500 Subject: [PATCH 01/14] Add JMH annotation --- .gitignore | 1 + modules/swagger-core/pom.xml | 94 +++++++++++++++++++ .../v3/core/filter/SpecFilterTest.java | 3 + 3 files changed, 98 insertions(+) diff --git a/.gitignore b/.gitignore index c8969adcb4..0a4bace89b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ atlassian-ide-plugin.xml sonar-project.properties test-output/ *.pyc +jmh-results.* \ No newline at end of file diff --git a/modules/swagger-core/pom.xml b/modules/swagger-core/pom.xml index 30e285f00f..abcaa19686 100644 --- a/modules/swagger-core/pom.xml +++ b/modules/swagger-core/pom.xml @@ -10,10 +10,93 @@ swagger-core swagger-core swagger-core + + 1.37 + src/main/java install + + org.codehaus.mojo + exec-maven-plugin + + + run-benchmarks + integration-test + + exec + + + test + java + + -classpath + + org.openjdk.jmh.Main + .* + -bm + avgt + -f + 1 + -tu + ms + -rff + jmh-results.csv + -o + jmh-results.txt + + -i + 1 + + -foe + true + + -wi + 0 + + -wm + BULK + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.4.3 + + + package + + shade + + + ${uberjar.name} + + + org.openjdk.jmh.Main + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + biz.aQute.bnd bnd-maven-plugin @@ -52,6 +135,17 @@ + + org.openjdk.jmh + jmh-core + ${jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + provided + jakarta.xml.bind jakarta.xml.bind-api diff --git a/modules/swagger-core/src/test/java/io/swagger/v3/core/filter/SpecFilterTest.java b/modules/swagger-core/src/test/java/io/swagger/v3/core/filter/SpecFilterTest.java index 6f32a71c09..2001fcc369 100644 --- a/modules/swagger-core/src/test/java/io/swagger/v3/core/filter/SpecFilterTest.java +++ b/modules/swagger-core/src/test/java/io/swagger/v3/core/filter/SpecFilterTest.java @@ -26,6 +26,7 @@ import io.swagger.v3.oas.models.tags.Tag; import org.apache.commons.lang3.StringUtils; import org.testng.annotations.Test; +import org.openjdk.jmh.annotations.*; import java.io.IOException; import java.util.HashSet; @@ -41,6 +42,7 @@ import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; +@State(Scope.Benchmark) public class SpecFilterTest { private static final String RESOURCE_RECURSIVE_MODELS = "specFiles/recursivemodels.json"; @@ -172,6 +174,7 @@ private void validateParameters(Operation operation) { } @Test(description = "it should clone everything concurrently") + @Benchmark public void cloneEverythingConcurrent() throws IOException { int numThreads = 10; final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH); From daf6f61785d698f9ebb9c1e32a991adf389c055d Mon Sep 17 00:00:00 2001 From: Benjamin Prud'homme Date: Mon, 19 Feb 2024 22:29:19 -0500 Subject: [PATCH 02/14] Fix properties --- modules/swagger-core/pom.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/swagger-core/pom.xml b/modules/swagger-core/pom.xml index abcaa19686..bd275fd900 100644 --- a/modules/swagger-core/pom.xml +++ b/modules/swagger-core/pom.xml @@ -10,9 +10,6 @@ swagger-core swagger-core swagger-core - - 1.37 - src/main/java install @@ -254,5 +251,6 @@ 0.60 0.0 3 + 1.37 From 076cea648256a166599eb6e73afef3ee86a0633d Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 21 Feb 2024 09:57:38 -0500 Subject: [PATCH 03/14] Fix whitespace. --- modules/swagger-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-core/pom.xml b/modules/swagger-core/pom.xml index bd275fd900..6bb0efce51 100644 --- a/modules/swagger-core/pom.xml +++ b/modules/swagger-core/pom.xml @@ -251,6 +251,6 @@ 0.60 0.0 3 - 1.37 + 1.37 From 4bc39f6713f6db31af8cfe566df9c4203c8a90c0 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 21 Feb 2024 10:04:24 -0500 Subject: [PATCH 04/14] Fix formatting. --- modules/swagger-core/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/swagger-core/pom.xml b/modules/swagger-core/pom.xml index 6bb0efce51..a9734eabe4 100644 --- a/modules/swagger-core/pom.xml +++ b/modules/swagger-core/pom.xml @@ -14,7 +14,7 @@ src/main/java install - + org.codehaus.mojo exec-maven-plugin @@ -132,7 +132,7 @@ - + org.openjdk.jmh jmh-core ${jmh.version} From 764d892ef742bcc445ba5638cd114cd323a44966 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 21 Feb 2024 10:04:53 -0500 Subject: [PATCH 05/14] Add newline at end of file. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0a4bace89b..8db301d372 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,4 @@ atlassian-ide-plugin.xml sonar-project.properties test-output/ *.pyc -jmh-results.* \ No newline at end of file +jmh-results.* From b7cc64db52e38ffaaa9fe6bed8a0fa33b10882a1 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 21 Feb 2024 10:19:11 -0500 Subject: [PATCH 06/14] Update Javadoc links. --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 86f7ce337e..6f7bd69a9d 100644 --- a/pom.xml +++ b/pom.xml @@ -170,7 +170,7 @@ UTF-8 1g - http://docs.oracle.com/javase/8/docs/api + http://docs.oracle.com/en/java/javase/21/docs/api ${javadoc.package.exclude} @@ -423,7 +423,7 @@ 1g true - https://docs.oracle.com/javase/8/docs/api + https://docs.oracle.com/en/java/javase/21/docs/api From 25023f24dd701023bd7409bd73b2e13eb3f5367d Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 21 Feb 2024 10:23:22 -0500 Subject: [PATCH 07/14] Skip Javadoc creation. For some reason, it's not working with the JMH addition. --- pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pom.xml b/pom.xml index 6f7bd69a9d..957d9c6ba7 100644 --- a/pom.xml +++ b/pom.xml @@ -664,5 +664,7 @@ 0.5.0 UTF-8 https://oss.sonatype.org/content/repositories/snapshots/ + + true From 655760be689094a67f03698699a6d6c955ffdb29 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 21 Feb 2024 10:59:11 -0500 Subject: [PATCH 08/14] Move variables outside benchmark. --- .../io/swagger/v3/core/filter/SpecFilterTest.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/swagger-core/src/test/java/io/swagger/v3/core/filter/SpecFilterTest.java b/modules/swagger-core/src/test/java/io/swagger/v3/core/filter/SpecFilterTest.java index 2001fcc369..8d6771c361 100644 --- a/modules/swagger-core/src/test/java/io/swagger/v3/core/filter/SpecFilterTest.java +++ b/modules/swagger-core/src/test/java/io/swagger/v3/core/filter/SpecFilterTest.java @@ -173,12 +173,20 @@ private void validateParameters(Operation operation) { } } + private OpenAPI openAPI; + + @Setup(Level.Trial) + public void setUp() throws IOException { + // RK: Move I/O outside the benchmark to reduce variability. + openAPI = getOpenAPI(RESOURCE_PATH); + } + + @Param({"10", "100", "1000"}) + private int numThreads; + @Test(description = "it should clone everything concurrently") @Benchmark public void cloneEverythingConcurrent() throws IOException { - int numThreads = 10; - final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH); - ThreadGroup tg = new ThreadGroup("SpecFilterTest" + "|" + System.currentTimeMillis()); final Map filteredMap = new ConcurrentHashMap<>(); for (int i = 0; i < numThreads; i++) { From d9c9575d7f66c484fe16388c444bc6a5e6cff004 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 21 Feb 2024 10:59:50 -0500 Subject: [PATCH 09/14] Update ignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8db301d372..af65eb1319 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ sonar-project.properties test-output/ *.pyc jmh-results.* +dependency-reduced-pom.xml From e45db45591e968eb4434cb3763761569bd244d33 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 21 Feb 2024 11:00:54 -0500 Subject: [PATCH 10/14] Switch benchmark modes. Let's have also throughput. --- modules/swagger-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-core/pom.xml b/modules/swagger-core/pom.xml index a9734eabe4..529decdd09 100644 --- a/modules/swagger-core/pom.xml +++ b/modules/swagger-core/pom.xml @@ -33,7 +33,7 @@ org.openjdk.jmh.Main .* -bm - avgt + all -f 1 -tu From d825e35d0d3038cd2e1d832751140b06184acddd Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 21 Feb 2024 11:09:44 -0500 Subject: [PATCH 11/14] Smaller param. Otherwise we'll kill the CI. Or, we should disable it. --- .../test/java/io/swagger/v3/core/filter/SpecFilterTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/swagger-core/src/test/java/io/swagger/v3/core/filter/SpecFilterTest.java b/modules/swagger-core/src/test/java/io/swagger/v3/core/filter/SpecFilterTest.java index 8d6771c361..0ef17d6a5c 100644 --- a/modules/swagger-core/src/test/java/io/swagger/v3/core/filter/SpecFilterTest.java +++ b/modules/swagger-core/src/test/java/io/swagger/v3/core/filter/SpecFilterTest.java @@ -181,7 +181,8 @@ public void setUp() throws IOException { openAPI = getOpenAPI(RESOURCE_PATH); } - @Param({"10", "100", "1000"}) + // @Param({"10", "100", "1000"}) + @Param({"10"}) private int numThreads; @Test(description = "it should clone everything concurrently") From 921ef807cc63a34d515ab963315c17fb2b4f1a70 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 21 Feb 2024 11:10:03 -0500 Subject: [PATCH 12/14] Add some default JMH arguments. --- modules/swagger-core/pom.xml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/modules/swagger-core/pom.xml b/modules/swagger-core/pom.xml index 529decdd09..57b3c1a51f 100644 --- a/modules/swagger-core/pom.xml +++ b/modules/swagger-core/pom.xml @@ -32,28 +32,33 @@ org.openjdk.jmh.Main .* + -bm all + -f 1 + -tu ms + -rff jmh-results.csv + -o jmh-results.txt - - -i - 1 -foe true - - -wi - 0 - - -wm - BULK + + + + + + + + + From f17d00f53673efa2489a170aa1dc4f200738c25d Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 21 Feb 2024 11:13:12 -0500 Subject: [PATCH 13/14] Use only one warm-up. --- modules/swagger-core/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/swagger-core/pom.xml b/modules/swagger-core/pom.xml index 57b3c1a51f..fdbc585990 100644 --- a/modules/swagger-core/pom.xml +++ b/modules/swagger-core/pom.xml @@ -54,8 +54,8 @@ - - + -wi + 1 From f8eef3bed7eb37d5e40ca60473269dd3026d11da Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 21 Feb 2024 11:22:27 -0500 Subject: [PATCH 14/14] Change benchmark modes. We really only need average time and throughput AFAIK. --- modules/swagger-core/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-core/pom.xml b/modules/swagger-core/pom.xml index fdbc585990..3fb056a030 100644 --- a/modules/swagger-core/pom.xml +++ b/modules/swagger-core/pom.xml @@ -34,7 +34,7 @@ .* -bm - all + avgt,thrpt -f 1