test: adjust benchmark to better represent real usage

This commit is contained in:
Gauthier Roebroeck 2022-07-16 17:35:52 +08:00
parent 6a674f1f4d
commit c76f7affb8
4 changed files with 49 additions and 11 deletions

View file

@ -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

View file

@ -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"))))
}
}

View file

@ -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))
}
}

View file

@ -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