Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance tests for loom-based backends #3611

Merged
merged 7 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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("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")))
filteredByNative.filterNot(p => (p.toString.contains("Loom") || p.toString.contains("nima") || p.toString.contains("perfTests")))
}

}
Expand Down Expand Up @@ -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, playServer, vertxServer, vertxServerCats)
.dependsOn(
core,
pekkoHttpServer,
http4sServer,
nettyServer,
nettyServerCats,
nettyServerLoom,
playServer,
vertxServer,
vertxServerCats,
nimaServer
)

// integrations

Expand Down
2 changes: 2 additions & 0 deletions perf-tests/README.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand Down Expand Up @@ -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])
}
32 changes: 32 additions & 0 deletions perf-tests/src/main/scala/sttp/tapir/perf/netty/loom/NettyId.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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

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)
}
39 changes: 39 additions & 0 deletions perf-tests/src/main/scala/sttp/tapir/perf/nima/Nima.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 sttp.tapir.server.nima.{Id, NimaServerInterpreter, NimaServerOptions}
import sttp.tapir.server.ServerEndpoint

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 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 { val _ = 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)
}
Loading