Skip to content

Commit

Permalink
feat: add separate benchmark tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Vazquez committed Oct 2, 2024
1 parent 6728a8f commit 6b22e9f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
8 changes: 8 additions & 0 deletions servers/graphql-kotlin-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ kotlin.sourceSets.getByName("benchmarks") {
}

benchmark {
configurations {
register("graphQLRequest") {
include("com.expediagroup.graphql.server.GraphQLServerRequest*")
}
register("graphQLResponse") {
include("com.expediagroup.graphql.server.GraphQLServerResponse*")
}
}
targets {
register("benchmarks") {
this as JvmBenchmarkTarget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import java.util.concurrent.TimeUnit

@State(Scope.Benchmark)
@Fork(value = 5, jvmArgsAppend = ["--add-modules=jdk.incubator.vector", "-Dfastjson2.readerVector=true"])
@Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
open class GraphQLServerBatchRequestDeserializationBenchmark {
@Warmup(iterations = 1, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 4, time = 5, timeUnit = TimeUnit.SECONDS)
open class GraphQLServerRequestBatchDeserializationBenchmark {
private val mapper = jacksonObjectMapper()
private lateinit var request: String
private lateinit var batchRequest: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import java.util.concurrent.TimeUnit

@State(Scope.Benchmark)
@Fork(value = 5, jvmArgsAppend = ["--add-modules=jdk.incubator.vector", "-Dfastjson2.readerVector=true"])
@Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Warmup(iterations = 1, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 4, time = 5, timeUnit = TimeUnit.SECONDS)
open class GraphQLServerRequestDeserializationBenchmark {
private val mapper = jacksonObjectMapper()
private lateinit var request: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import java.util.concurrent.TimeUnit

@State(Scope.Benchmark)
@Fork(value = 5, jvmArgsAppend = ["--add-modules=jdk.incubator.vector", "-Dfastjson2.readerVector=true"])
@Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
open class GraphQLServerBatchResponseSerializationBenchmark {
@Warmup(iterations = 1, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 4, time = 5, timeUnit = TimeUnit.SECONDS)
open class GraphQLServerResponseBatchSerializationBenchmark {
private val mapper = jacksonObjectMapper()
private lateinit var batchResponse: GraphQLBatchResponse

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.expediagroup.graphql.server

import com.alibaba.fastjson2.JSON
import com.alibaba.fastjson2.JSONWriter
import com.expediagroup.graphql.server.testtypes.GraphQLResponse
import com.expediagroup.graphql.server.types.GraphQLResponse
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.openjdk.jmh.annotations.Benchmark
Expand All @@ -32,11 +32,11 @@ import java.util.concurrent.TimeUnit

@State(Scope.Benchmark)
@Fork(value = 5, jvmArgsAppend = ["--add-modules=jdk.incubator.vector", "-Dfastjson2.readerVector=true"])
@Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Warmup(iterations = 1, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 4, time = 5, timeUnit = TimeUnit.SECONDS)
open class GraphQLServerResponseSerializationBenchmark {
private val mapper = jacksonObjectMapper()
private lateinit var response: GraphQLResponse
private lateinit var response: GraphQLResponse<Map<String, Any?>>

@Setup
fun setUp() {
Expand Down
2 changes: 1 addition & 1 deletion servers/graphql-kotlin-spring-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tasks {
limit {
counter = "INSTRUCTION"
value = "COVEREDRATIO"
minimum = "0.87".toBigDecimal()
minimum = "0.86".toBigDecimal()
}
limit {
counter = "BRANCH"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Expedia, Inc
* Copyright 2024 Expedia, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,14 +29,14 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import graphql.GraphQL
import graphql.schema.GraphQLSchema
import io.mockk.every
import io.mockk.mockk
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.springframework.boot.autoconfigure.AutoConfigurations
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.reactive.HandlerMapping
import org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter
import reactor.core.publisher.Flux
import java.time.Duration
Expand Down Expand Up @@ -73,7 +73,7 @@ class SubscriptionConfigurationTest {

assertThat(ctx).hasSingleBean(SubscriptionWebSocketHandler::class.java)
assertThat(ctx).hasSingleBean(WebSocketHandlerAdapter::class.java)
assertThat(ctx).hasSingleBean(HandlerMapping::class.java)
assertThat(ctx).hasBean("subscriptionHandlerMapping")
}
}

Expand Down Expand Up @@ -102,10 +102,9 @@ class SubscriptionConfigurationTest {

assertThat(ctx).hasSingleBean(ApolloSubscriptionWebSocketHandler::class.java)

assertThat(ctx).hasSingleBean(WebSocketHandlerAdapter::class.java)
assertThat(ctx).getBean(WebSocketHandlerAdapter::class.java)
assertThat(ctx).hasBean("webSocketHandlerAdapter")
assertThat(ctx).getBean("webSocketHandlerAdapter")
.isSameAs(customConfiguration.webSocketHandlerAdapter())
assertThat(ctx).hasSingleBean(HandlerMapping::class.java)
}
}

Expand Down Expand Up @@ -146,7 +145,9 @@ class SubscriptionConfigurationTest {
@Bean
fun subscription(): Subscription = SimpleSubscription()
@Bean
fun webSocketHandlerAdapter(): WebSocketHandlerAdapter = mockk()
fun webSocketHandlerAdapter(): WebSocketHandlerAdapter = mockk {
every { order } returns 1
}
}

// GraphQL spec requires at least single query to be present as Query type is needed to run introspection queries
Expand Down

0 comments on commit 6b22e9f

Please sign in to comment.