From c76f7affb88f839c15d7b0aeadc1080591c38fbf Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Sat, 16 Jul 2022 17:35:52 +0800 Subject: [PATCH] test: adjust benchmark to better represent real usage --- .../komga/benchmark/AbstractBenchmark.kt | 2 +- .../komga/benchmark/rest/BrowseBenchmark.kt | 41 +++++++++++++++++++ ...ationBenchmark.kt => UnsortedBenchmark.kt} | 11 +---- .../resources/application-benchmark.yml | 6 ++- 4 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/BrowseBenchmark.kt rename komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/{PaginationBenchmark.kt => UnsortedBenchmark.kt} (75%) diff --git a/komga/src/benchmark/kotlin/org/gotson/komga/benchmark/AbstractBenchmark.kt b/komga/src/benchmark/kotlin/org/gotson/komga/benchmark/AbstractBenchmark.kt index ab0011dff..1d98e3058 100644 --- a/komga/src/benchmark/kotlin/org/gotson/komga/benchmark/AbstractBenchmark.kt +++ b/komga/src/benchmark/kotlin/org/gotson/komga/benchmark/AbstractBenchmark.kt @@ -38,7 +38,7 @@ abstract class AbstractBenchmark { val resultFile = Paths.get(benchmarkProperties.resultFolder, "${this.javaClass.name}.$extension").absolutePathString() val opt: Options = OptionsBuilder() .include("\\." + this.javaClass.simpleName + "\\.") // set the class name regex for benchmarks to search for to the current class - .warmupIterations(benchmarkProperties.warmupIterations) + .apply { if (benchmarkProperties.warmupIterations > 0) warmupIterations(benchmarkProperties.warmupIterations) } .measurementIterations(benchmarkProperties.measurementIterations) .forks(0) // do not use forking or the benchmark methods will not see references stored within its class .threads(1) // do not use multiple threads diff --git a/komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/BrowseBenchmark.kt b/komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/BrowseBenchmark.kt new file mode 100644 index 000000000..41501265d --- /dev/null +++ b/komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/BrowseBenchmark.kt @@ -0,0 +1,41 @@ +package org.gotson.komga.benchmark.rest + +import org.openjdk.jmh.annotations.Benchmark +import org.openjdk.jmh.annotations.Level +import org.openjdk.jmh.annotations.OutputTimeUnit +import org.openjdk.jmh.annotations.Param +import org.openjdk.jmh.annotations.Setup +import org.springframework.data.domain.PageRequest +import org.springframework.data.domain.Sort +import java.util.concurrent.TimeUnit + +@OutputTimeUnit(TimeUnit.MILLISECONDS) +class BrowseBenchmark : AbstractRestBenchmark() { + + companion object { + private lateinit var biggestSeriesId: String + } + + @Param("20", "100", "100", "200", "500") + private var pageSize: Int = DEFAULT_PAGE_SIZE + + @Setup(Level.Trial) + override fun prepareData() { + super.prepareData() + + // find series with most books + biggestSeriesId = seriesController.getAllSeries(principal, page = PageRequest.of(0, 1, Sort.by(Sort.Order.desc("booksCount")))) + .content.first() + .id + } + + @Benchmark + fun browseSeries() { + seriesController.getAllSeries(principal, page = PageRequest.of(0, pageSize, Sort.by(Sort.Order.asc("metadata.titleSort")))) + } + + @Benchmark + fun browseSeriesBooks() { + seriesController.getAllBooksBySeries(principal, biggestSeriesId, page = PageRequest.of(0, pageSize, Sort.by(Sort.Order.asc("metadata.numberSort")))) + } +} diff --git a/komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/PaginationBenchmark.kt b/komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/UnsortedBenchmark.kt similarity index 75% rename from komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/PaginationBenchmark.kt rename to komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/UnsortedBenchmark.kt index 0ec4d1a72..c36dc8da1 100644 --- a/komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/PaginationBenchmark.kt +++ b/komga/src/benchmark/kotlin/org/gotson/komga/benchmark/rest/UnsortedBenchmark.kt @@ -3,7 +3,6 @@ package org.gotson.komga.benchmark.rest import org.openjdk.jmh.annotations.Benchmark import org.openjdk.jmh.annotations.Level import org.openjdk.jmh.annotations.OutputTimeUnit -import org.openjdk.jmh.annotations.Param import org.openjdk.jmh.annotations.Setup import org.springframework.data.domain.PageRequest import org.springframework.data.domain.Pageable @@ -11,14 +10,13 @@ import org.springframework.data.domain.Sort import java.util.concurrent.TimeUnit @OutputTimeUnit(TimeUnit.MILLISECONDS) -class PaginationBenchmark : AbstractRestBenchmark() { +class UnsortedBenchmark : AbstractRestBenchmark() { companion object { private lateinit var biggestSeriesId: String } - @Param("20", "100", "500", "1000", "5000") - private var pageSize: Int = DEFAULT_PAGE_SIZE + private var pageSize: Int = 2000 @Setup(Level.Trial) override fun prepareData() { @@ -39,9 +37,4 @@ class PaginationBenchmark : AbstractRestBenchmark() { fun getAllBooks() { bookController.getAllBooks(principal, page = Pageable.ofSize(pageSize)) } - - @Benchmark - fun getSeriesBooks() { - seriesController.getAllBooksBySeries(principal, biggestSeriesId, page = Pageable.ofSize(pageSize)) - } } diff --git a/komga/src/benchmark/resources/application-benchmark.yml b/komga/src/benchmark/resources/application-benchmark.yml index cdea858b3..cc4eb16b2 100644 --- a/komga/src/benchmark/resources/application-benchmark.yml +++ b/komga/src/benchmark/resources/application-benchmark.yml @@ -5,6 +5,9 @@ benchmark: measurement-iterations: 5 warmup-iterations: 1 mode: averagetime + # measurement-iterations: 1 + # warmup-iterations: 0 + # mode: singleshottime result-format: text komga: config-dir: ${rootDir}/config-dir @@ -21,4 +24,5 @@ spring: data-directory: \${komga.config-dir}/artemis/\${komga.workspace} #logging: # level: -# org.jooq: DEBUG +# root: ERROR +# org.jooq.tools.LoggerListener: DEBUG