From ca6860f9a1aa8cb9fea30074b414a11e8309eebd Mon Sep 17 00:00:00 2001 From: kciesielski Date: Thu, 7 Mar 2024 13:15:14 +0100 Subject: [PATCH 1/6] Add netty-loom --- build.sbt | 2 +- .../sttp/tapir/perf/apis/Endpoints.scala | 2 ++ .../sttp/tapir/perf/netty/loom/NettyId.scala | 36 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 perf-tests/src/main/scala/sttp/tapir/perf/netty/loom/NettyId.scala diff --git a/build.sbt b/build.sbt index 68155a7ace..6a4a536f6f 100644 --- a/build.sbt +++ b/build.sbt @@ -538,7 +538,7 @@ lazy val perfTests: ProjectMatrix = (projectMatrix in file("perf-tests")) Test / run / javaOptions --= perfServerJavaOptions ) .jvmPlatform(scalaVersions = List(scala2_13)) - .dependsOn(core, pekkoHttpServer, http4sServer, nettyServer, nettyServerCats, playServer, vertxServer, vertxServerCats) + .dependsOn(core, pekkoHttpServer, http4sServer, nettyServer, nettyServerCats, nettyServerLoom, playServer, vertxServer, vertxServerCats) // integrations diff --git a/perf-tests/src/main/scala/sttp/tapir/perf/apis/Endpoints.scala b/perf-tests/src/main/scala/sttp/tapir/perf/apis/Endpoints.scala index 9359682160..a91ae77f22 100644 --- a/perf-tests/src/main/scala/sttp/tapir/perf/apis/Endpoints.scala +++ b/perf-tests/src/main/scala/sttp/tapir/perf/apis/Endpoints.scala @@ -3,6 +3,7 @@ package sttp.tapir.perf.apis import cats.effect.IO import sttp.tapir._ import sttp.tapir.perf.Common._ +import sttp.tapir.server.netty.loom.Id import sttp.tapir.server.ServerEndpoint import sttp.tapir.server.model.EndpointExtensions._ @@ -66,4 +67,5 @@ trait Endpoints { def genEndpointsFuture(count: Int): List[ServerEndpoint[Any, Future]] = genServerEndpoints(count)(Future.successful) def genEndpointsIO(count: Int): List[ServerEndpoint[Any, IO]] = genServerEndpoints(count)(IO.pure) + def genEndpointsId(count: Int): List[ServerEndpoint[Any, Id]] = genServerEndpoints[Id](count)(x => x: Id[String]) } diff --git a/perf-tests/src/main/scala/sttp/tapir/perf/netty/loom/NettyId.scala b/perf-tests/src/main/scala/sttp/tapir/perf/netty/loom/NettyId.scala new file mode 100644 index 0000000000..8dd3f579e6 --- /dev/null +++ b/perf-tests/src/main/scala/sttp/tapir/perf/netty/loom/NettyId.scala @@ -0,0 +1,36 @@ +package sttp.tapir.perf.netty.loom + +import cats.effect.IO +import sttp.tapir.perf.apis._ +import sttp.tapir.perf.Common._ +import sttp.tapir.server.netty.loom._ +import sttp.tapir.server.ServerEndpoint + +import scala.concurrent.ExecutionContext +import ExecutionContext.Implicits.global +import scala.concurrent.Future + +object Tapir extends Endpoints + +object NettyId { + + def runServer(endpoints: List[ServerEndpoint[Any, Id]], withServerLog: Boolean = false): IO[ServerRunner.KillSwitch] = { + val declaredPort = Port + val declaredHost = "0.0.0.0" + val serverOptions = buildOptions(NettyIdServerOptions.customiseInterceptors, withServerLog) + // Starting netty server + val serverBinding: NettyIdServerBinding = + NettyIdServer(serverOptions) + .port(declaredPort) + .host(declaredHost) + .addEndpoints(endpoints) + .start() + IO(IO(serverBinding.stop())) + } +} + +object TapirServer extends ServerRunner { override def start = NettyId.runServer(Tapir.genEndpointsId(1)) } +object TapirMultiServer extends ServerRunner { override def start = NettyId.runServer(Tapir.genEndpointsId(128)) } +object TapirInterceptorMultiServer extends ServerRunner { + override def start = NettyId.runServer(Tapir.genEndpointsId(128), withServerLog = true) +} From f1698ee5b91882364899c4266d06a3966f6bfe5a Mon Sep 17 00:00:00 2001 From: kciesielski Date: Thu, 7 Mar 2024 13:40:21 +0100 Subject: [PATCH 2/6] Add Helidon Nima --- build.sbt | 13 +++++- .../scala/sttp/tapir/perf/nima/Nima.scala | 44 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 perf-tests/src/main/scala/sttp/tapir/perf/nima/Nima.scala diff --git a/build.sbt b/build.sbt index 6a4a536f6f..8cc38a9d1c 100644 --- a/build.sbt +++ b/build.sbt @@ -538,7 +538,18 @@ lazy val perfTests: ProjectMatrix = (projectMatrix in file("perf-tests")) Test / run / javaOptions --= perfServerJavaOptions ) .jvmPlatform(scalaVersions = List(scala2_13)) - .dependsOn(core, pekkoHttpServer, http4sServer, nettyServer, nettyServerCats, nettyServerLoom, playServer, vertxServer, vertxServerCats) + .dependsOn( + core, + pekkoHttpServer, + http4sServer, + nettyServer, + nettyServerCats, + nettyServerLoom, + playServer, + vertxServer, + vertxServerCats, + nimaServer + ) // integrations diff --git a/perf-tests/src/main/scala/sttp/tapir/perf/nima/Nima.scala b/perf-tests/src/main/scala/sttp/tapir/perf/nima/Nima.scala new file mode 100644 index 0000000000..167bbd0908 --- /dev/null +++ b/perf-tests/src/main/scala/sttp/tapir/perf/nima/Nima.scala @@ -0,0 +1,44 @@ +package sttp.tapir.perf.nima + +import cats.effect.IO +import sttp.tapir.perf.apis._ +import sttp.tapir.perf.Common._ +import io.helidon.webserver.WebServer +import sttp.tapir.server.nima.{Id, NimaServerInterpreter, NimaServerOptions} +import sttp.tapir.server.ServerEndpoint + +import scala.concurrent.ExecutionContext +import ExecutionContext.Implicits.global +import scala.concurrent.Future + +object Tapir extends Endpoints { + def genEndpointsNId(count: Int): List[ServerEndpoint[Any, Id]] = genServerEndpoints[Id](count)(x => x: Id[String]) +} + +object Nima { + + def runServer(endpoints: List[ServerEndpoint[Any, Id]], withServerLog: Boolean = false): IO[ServerRunner.KillSwitch] = { + val declaredPort = Port + val declaredHost = "0.0.0.0" + val serverOptions = buildOptions(NimaServerOptions.customiseInterceptors, withServerLog) + // Starting Nima server + + val handler = NimaServerInterpreter(serverOptions).toHandler(endpoints) + val server = WebServer + .builder() + .routing { builder => + builder.any(handler) + () + } + .port(declaredPort) + .build() + .start() + IO(IO(server.stop())) + } +} + +object TapirServer extends ServerRunner { override def start = Nima.runServer(Tapir.genEndpointsNId(1)) } +object TapirMultiServer extends ServerRunner { override def start = Nima.runServer(Tapir.genEndpointsNId(128)) } +object TapirInterceptorMultiServer extends ServerRunner { + override def start = Nima.runServer(Tapir.genEndpointsNId(128), withServerLog = true) +} From defdf7e3eb758923fd1224af05df7d3f4b6f7523 Mon Sep 17 00:00:00 2001 From: kciesielski Date: Fri, 15 Mar 2024 14:04:07 +0100 Subject: [PATCH 3/6] Add perf-tests to "loom-based-projects" --- build.sbt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 8cc38a9d1c..4763b1d448 100644 --- a/build.sbt +++ b/build.sbt @@ -256,13 +256,13 @@ lazy val allAggregates: Seq[ProjectReference] = { } if (sys.env.isDefinedAt("ONLY_LOOM")) { println("[info] ONLY_LOOM defined, including only loom-based projects") - filteredByNative.filter(p => (p.toString.contains("Loom") || p.toString.contains("nima"))) + filteredByNative.filter(p => (p.toString.contains("Loom") || p.toString.contains("nima") || p.toString.contains("perf-tests"))) } else if (sys.env.isDefinedAt("ALSO_LOOM")) { println("[info] ALSO_LOOM defined, including also loom-based projects") filteredByNative } else { println("[info] ONLY_LOOM *not* defined, *not* including loom-based-projects") - filteredByNative.filterNot(p => (p.toString.contains("Loom") || p.toString.contains("nima"))) + filteredByNative.filterNot(p => (p.toString.contains("Loom") || p.toString.contains("nima") || p.toString.contains("perf-tests"))) } } From 546b2ec7ba6d75bea69a69897dc00c190a5dd82e Mon Sep 17 00:00:00 2001 From: kciesielski Date: Fri, 15 Mar 2024 14:06:05 +0100 Subject: [PATCH 4/6] Add note about Loom to README --- perf-tests/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/perf-tests/README.md b/perf-tests/README.md index 4d58194842..d6a5dc2186 100644 --- a/perf-tests/README.md +++ b/perf-tests/README.md @@ -1,5 +1,7 @@ # Performance tests +To work with performance tests, make sure you are running JDK 21+, and that the `ALSO_LOOM` environment variable is set, because the `perf-tests` project includes `tapir-netty-loom` and `tapir-nima`, which require Loom JDK feature to be available. + Performance tests are executed by running `PerfTestSuiteRunner`, which is a standard "Main" Scala application, configured by command line parameters. It executes a sequence of tests, where each test consist of: From c978be12883e3f525b3feee76806aa9d04d57f95 Mon Sep 17 00:00:00 2001 From: kciesielski Date: Fri, 15 Mar 2024 18:51:03 +0100 Subject: [PATCH 5/6] Fix predicate --- build.sbt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 4763b1d448..606784cecd 100644 --- a/build.sbt +++ b/build.sbt @@ -256,13 +256,13 @@ lazy val allAggregates: Seq[ProjectReference] = { } if (sys.env.isDefinedAt("ONLY_LOOM")) { println("[info] ONLY_LOOM defined, including only loom-based projects") - filteredByNative.filter(p => (p.toString.contains("Loom") || p.toString.contains("nima") || p.toString.contains("perf-tests"))) + filteredByNative.filter(p => (p.toString.contains("Loom") || p.toString.contains("nima") || p.toString.contains("perfTests"))) } else if (sys.env.isDefinedAt("ALSO_LOOM")) { println("[info] ALSO_LOOM defined, including also loom-based projects") filteredByNative } else { println("[info] ONLY_LOOM *not* defined, *not* including loom-based-projects") - filteredByNative.filterNot(p => (p.toString.contains("Loom") || p.toString.contains("nima") || p.toString.contains("perf-tests"))) + filteredByNative.filterNot(p => (p.toString.contains("Loom") || p.toString.contains("nima") || p.toString.contains("perfTests"))) } } From ac66c27f650449f229017c583b6a7e14a64736d2 Mon Sep 17 00:00:00 2001 From: kciesielski Date: Fri, 15 Mar 2024 19:10:41 +0100 Subject: [PATCH 6/6] Clear warnings --- .../main/scala/sttp/tapir/perf/netty/loom/NettyId.scala | 4 ---- .../src/main/scala/sttp/tapir/perf/nima/Nima.scala | 9 ++------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/perf-tests/src/main/scala/sttp/tapir/perf/netty/loom/NettyId.scala b/perf-tests/src/main/scala/sttp/tapir/perf/netty/loom/NettyId.scala index 8dd3f579e6..0fe76cedb6 100644 --- a/perf-tests/src/main/scala/sttp/tapir/perf/netty/loom/NettyId.scala +++ b/perf-tests/src/main/scala/sttp/tapir/perf/netty/loom/NettyId.scala @@ -6,10 +6,6 @@ import sttp.tapir.perf.Common._ import sttp.tapir.server.netty.loom._ import sttp.tapir.server.ServerEndpoint -import scala.concurrent.ExecutionContext -import ExecutionContext.Implicits.global -import scala.concurrent.Future - object Tapir extends Endpoints object NettyId { diff --git a/perf-tests/src/main/scala/sttp/tapir/perf/nima/Nima.scala b/perf-tests/src/main/scala/sttp/tapir/perf/nima/Nima.scala index 167bbd0908..1a4cdef2b5 100644 --- a/perf-tests/src/main/scala/sttp/tapir/perf/nima/Nima.scala +++ b/perf-tests/src/main/scala/sttp/tapir/perf/nima/Nima.scala @@ -1,16 +1,12 @@ package sttp.tapir.perf.nima import cats.effect.IO +import io.helidon.webserver.WebServer import sttp.tapir.perf.apis._ import sttp.tapir.perf.Common._ -import io.helidon.webserver.WebServer import sttp.tapir.server.nima.{Id, NimaServerInterpreter, NimaServerOptions} import sttp.tapir.server.ServerEndpoint -import scala.concurrent.ExecutionContext -import ExecutionContext.Implicits.global -import scala.concurrent.Future - object Tapir extends Endpoints { def genEndpointsNId(count: Int): List[ServerEndpoint[Any, Id]] = genServerEndpoints[Id](count)(x => x: Id[String]) } @@ -19,7 +15,6 @@ object Nima { def runServer(endpoints: List[ServerEndpoint[Any, Id]], withServerLog: Boolean = false): IO[ServerRunner.KillSwitch] = { val declaredPort = Port - val declaredHost = "0.0.0.0" val serverOptions = buildOptions(NimaServerOptions.customiseInterceptors, withServerLog) // Starting Nima server @@ -33,7 +28,7 @@ object Nima { .port(declaredPort) .build() .start() - IO(IO(server.stop())) + IO(IO { val _ = server.stop() }) } }