From 8e642fa916cb669a87d5cac8fd98cc62a316c6cc Mon Sep 17 00:00:00 2001 From: adamw Date: Fri, 18 Mar 2022 08:56:15 +0100 Subject: [PATCH 1/7] Add logging --- perf-tests/src/main/resources/logback.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 perf-tests/src/main/resources/logback.xml diff --git a/perf-tests/src/main/resources/logback.xml b/perf-tests/src/main/resources/logback.xml new file mode 100644 index 0000000000..e6cee15ae7 --- /dev/null +++ b/perf-tests/src/main/resources/logback.xml @@ -0,0 +1,12 @@ + + + + + %date [%thread] %-5level %logger{36} - %msg%n + + + + + + + \ No newline at end of file From 55e8e9de7cae43d41fadff6e3df974f304725544 Mon Sep 17 00:00:00 2001 From: adamw Date: Fri, 18 Mar 2022 08:59:23 +0100 Subject: [PATCH 2/7] Fix compilation warnings --- perf-tests/src/main/scala/AkkaHttp.scala | 13 +++++++------ perf-tests/src/main/scala/Common.scala | 4 ++-- perf-tests/src/main/scala/Http4s.scala | 6 +++--- perf-tests/src/test/scala/Simulations.scala | 15 ++++++++++----- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/perf-tests/src/main/scala/AkkaHttp.scala b/perf-tests/src/main/scala/AkkaHttp.scala index fda90792b0..ad4ebb026b 100644 --- a/perf-tests/src/main/scala/AkkaHttp.scala +++ b/perf-tests/src/main/scala/AkkaHttp.scala @@ -5,10 +5,11 @@ import akka.actor.ActorSystem import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.Route import akka.http.scaladsl.Http -import scala.concurrent.Future + +import scala.concurrent.{ExecutionContextExecutor, Future} object Vanilla { - val router = (nRoutes: Int) => + val router: Int => Route = (nRoutes: Int) => concat( (0 to nRoutes).map((n: Int) => get { @@ -21,7 +22,7 @@ object Vanilla { } object Tapir { - val router = (nRoutes: Int) => + val router: Int => Route = (nRoutes: Int) => AkkaHttpServerInterpreter().toRoute( (0 to nRoutes) .map((n: Int) => @@ -34,10 +35,10 @@ object Tapir { } object AkkaHttp { - implicit val actorSystem = ActorSystem("akka-http") - implicit val executionContext = actorSystem.dispatcher + implicit val actorSystem: ActorSystem = ActorSystem("akka-http") + implicit val executionContext: ExecutionContextExecutor = actorSystem.dispatcher - def runServer(router: Route) = { + def runServer(router: Route): Unit = { Http() .newServerAt("127.0.0.1", 8080) .bind(router) diff --git a/perf-tests/src/main/scala/Common.scala b/perf-tests/src/main/scala/Common.scala index b880f5a9ce..97259a7870 100644 --- a/perf-tests/src/main/scala/Common.scala +++ b/perf-tests/src/main/scala/Common.scala @@ -4,13 +4,13 @@ import sttp.tapir._ import scala.io.StdIn object Common { - def genTapirEndpoint(n: Int) = endpoint.get + def genTapirEndpoint(n: Int): PublicEndpoint[Int, String, String, Any] = endpoint.get .in("path" + n.toString) .in(path[Int]("id")) .errorOut(stringBody) .out(stringBody) - def blockServer() = { + def blockServer(): Unit = { println(Console.BLUE + "Server now online. Please navigate to http://localhost:8080/path0/1\nPress RETURN to stop..." + Console.RESET) StdIn.readLine() println("Server terminated") diff --git a/perf-tests/src/main/scala/Http4s.scala b/perf-tests/src/main/scala/Http4s.scala index 0112d79957..d8fca5de3e 100644 --- a/perf-tests/src/main/scala/Http4s.scala +++ b/perf-tests/src/main/scala/Http4s.scala @@ -6,12 +6,12 @@ import cats.syntax.all._ import org.http4s._ import org.http4s.dsl._ import org.http4s.implicits._ -import org.http4s.server.blaze.BlazeServerBuilder import org.http4s.server.Router +import org.http4s.blaze.server.BlazeServerBuilder import sttp.tapir.server.http4s.Http4sServerInterpreter object Vanilla { - val router = (nRoutes: Int) => + val router: Int => HttpRoutes[IO] = (nRoutes: Int) => Router( (0 to nRoutes).map((n: Int) => ("/path" + n.toString) -> { @@ -26,7 +26,7 @@ object Vanilla { } object Tapir { - val router = (nRoutes: Int) => + val router: Int => HttpRoutes[IO] = (nRoutes: Int) => Router("/" -> { Http4sServerInterpreter[IO]().toRoutes( (0 to nRoutes) diff --git a/perf-tests/src/test/scala/Simulations.scala b/perf-tests/src/test/scala/Simulations.scala index f82712db73..8cc1275d8b 100644 --- a/perf-tests/src/test/scala/Simulations.scala +++ b/perf-tests/src/test/scala/Simulations.scala @@ -1,20 +1,25 @@ package perfTests import io.gatling.core.Predef._ +import io.gatling.core.structure.{PopulationBuilder, ScenarioBuilder} import io.gatling.http.Predef._ +import scala.concurrent.duration.DurationInt + object CommonSimulations { - val scn = scenario("get plaintext") - .during(5 * 60) { + private val duration = 5.minutes + private val userCount = 100 + private val baseUrl = "http://127.0.0.1:8080" + + val scn: ScenarioBuilder = scenario("get plaintext") + .during(duration.toSeconds.toInt) { exec( http("first plaintext") .get("/4") ) } - val userCount = 100 - val baseUrl = "http://127.0.0.1:8080" - def genericInjection(n: Int) = { + def genericInjection(n: Int): PopulationBuilder = { val httpProtocol = http.baseUrl(baseUrl + "/path" + n.toString) scn.inject(atOnceUsers(userCount)).protocols(httpProtocol) } From 00b8a569613e0a4a9ac64ae01ba0259a45416b99 Mon Sep 17 00:00:00 2001 From: adamw Date: Fri, 18 Mar 2022 09:00:27 +0100 Subject: [PATCH 3/7] Add packages --- .../results/100users-5min-09-03-2022-ec2.md | 32 +++++++++---------- .../{ => sttp/tapir/perf}/AkkaHttp.scala | 11 ++++--- .../scala/{ => sttp/tapir/perf}/Common.scala | 5 +-- .../scala/{ => sttp/tapir/perf}/Http4s.scala | 9 +++--- .../{ => sttp/tapir/perf}/Simulations.scala | 2 +- 5 files changed, 31 insertions(+), 28 deletions(-) rename perf-tests/src/main/scala/{ => sttp/tapir/perf}/AkkaHttp.scala (92%) rename perf-tests/src/main/scala/{ => sttp/tapir/perf}/Common.scala (83%) rename perf-tests/src/main/scala/{ => sttp/tapir/perf}/Http4s.scala (85%) rename perf-tests/src/test/scala/{ => sttp/tapir/perf}/Simulations.scala (97%) diff --git a/perf-tests/results/100users-5min-09-03-2022-ec2.md b/perf-tests/results/100users-5min-09-03-2022-ec2.md index 4bc3ba344b..51d5eeaa67 100644 --- a/perf-tests/results/100users-5min-09-03-2022-ec2.md +++ b/perf-tests/results/100users-5min-09-03-2022-ec2.md @@ -11,17 +11,17 @@ Network communication through local IP on a shared EC2 network; ## Summary ``` Name : requests sent -[1] perfTests.AkkaHttp.TapirMultiServer : 568554 -[2] perfTests.AkkaHttp.TapirServer : 1310373 -[3] perfTests.AkkaHttp.VanillaMultiServer : 1301316 -[4] perfTests.AkkaHttp.VanillaServer : 1311758 -[5] perfTests.Http4s.TapirMultiServer : 368887 -[6] perfTests.Http4s.TapirServer : 788788 -[7] perfTests.Http4s.VanillaMultiServer : 1074490 -[8] perfTests.Http4s.VanillaServer : 1235687 +[1] sttp.tapir.perf.TapirMultiServer : 568554 +[2] sttp.tapir.perf.TapirServer : 1310373 +[3] sttp.tapir.perf.VanillaMultiServer : 1301316 +[4] sttp.tapir.perf.VanillaServer : 1311758 +[5] sttp.tapir.perf.TapirMultiServer : 368887 +[6] sttp.tapir.perf.TapirServer : 788788 +[7] sttp.tapir.perf.VanillaMultiServer : 1074490 +[8] sttp.tapir.perf.VanillaServer : 1235687 ``` ## Full results -### [1] perfTests.AkkaHttp.TapirMultiServer +### [1] sttp.tapir.perf.TapirMultiServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -42,7 +42,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [2] perfTests.AkkaHttp.TapirServer +### [2] sttp.tapir.perf.TapirServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -63,7 +63,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [3] perfTests.AkkaHttp.VanillaMultiServer +### [3] sttp.tapir.perf.VanillaMultiServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -84,7 +84,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [4] perfTests.AkkaHttp.VanillaServer +### [4] sttp.tapir.perf.VanillaServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -105,7 +105,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [5] perfTests.Http4s.TapirMultiServer +### [5] sttp.tapir.perf.TapirMultiServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -126,7 +126,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [6] perfTests.Http4s.TapirServer +### [6] sttp.tapir.perf.TapirServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -147,7 +147,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [7] perfTests.Http4s.VanillaMultiServer +### [7] sttp.tapir.perf.VanillaMultiServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -168,7 +168,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [8] perfTests.Http4s.VanillaServer +### [8] sttp.tapir.perf.VanillaServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- diff --git a/perf-tests/src/main/scala/AkkaHttp.scala b/perf-tests/src/main/scala/sttp/tapir/perf/AkkaHttp.scala similarity index 92% rename from perf-tests/src/main/scala/AkkaHttp.scala rename to perf-tests/src/main/scala/sttp/tapir/perf/AkkaHttp.scala index ad4ebb026b..b507c1c2ee 100644 --- a/perf-tests/src/main/scala/AkkaHttp.scala +++ b/perf-tests/src/main/scala/sttp/tapir/perf/AkkaHttp.scala @@ -1,10 +1,11 @@ -package perfTests.AkkaHttp +package sttp.tapir.perf -import sttp.tapir.server.akkahttp.AkkaHttpServerInterpreter import akka.actor.ActorSystem +import akka.http.scaladsl.Http import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.Route -import akka.http.scaladsl.Http +import sttp.tapir.perf +import sttp.tapir.server.akkahttp.AkkaHttpServerInterpreter import scala.concurrent.{ExecutionContextExecutor, Future} @@ -26,7 +27,7 @@ object Tapir { AkkaHttpServerInterpreter().toRoute( (0 to nRoutes) .map((n: Int) => - perfTests.Common + perf.Common .genTapirEndpoint(n) .serverLogic((id: Int) => Future.successful(Right((id + n).toString)): Future[Either[String, String]]) ) @@ -42,7 +43,7 @@ object AkkaHttp { Http() .newServerAt("127.0.0.1", 8080) .bind(router) - .flatMap((x) => { perfTests.Common.blockServer(); x.unbind() }) + .flatMap((x) => { Common.blockServer(); x.unbind() }) .onComplete(_ => actorSystem.terminate()) } } diff --git a/perf-tests/src/main/scala/Common.scala b/perf-tests/src/main/scala/sttp/tapir/perf/Common.scala similarity index 83% rename from perf-tests/src/main/scala/Common.scala rename to perf-tests/src/main/scala/sttp/tapir/perf/Common.scala index 97259a7870..d44b39738d 100644 --- a/perf-tests/src/main/scala/Common.scala +++ b/perf-tests/src/main/scala/sttp/tapir/perf/Common.scala @@ -1,6 +1,7 @@ -package perfTests +package sttp.tapir.perf + +import sttp.tapir.{PublicEndpoint, endpoint, path, stringBody} -import sttp.tapir._ import scala.io.StdIn object Common { diff --git a/perf-tests/src/main/scala/Http4s.scala b/perf-tests/src/main/scala/sttp/tapir/perf/Http4s.scala similarity index 85% rename from perf-tests/src/main/scala/Http4s.scala rename to perf-tests/src/main/scala/sttp/tapir/perf/Http4s.scala index d8fca5de3e..9087c5958d 100644 --- a/perf-tests/src/main/scala/Http4s.scala +++ b/perf-tests/src/main/scala/sttp/tapir/perf/Http4s.scala @@ -1,13 +1,14 @@ -package perfTests.Http4s +package sttp.tapir.perf import cats.effect._ import cats.effect.unsafe.implicits.global import cats.syntax.all._ import org.http4s._ +import org.http4s.blaze.server.BlazeServerBuilder import org.http4s.dsl._ import org.http4s.implicits._ import org.http4s.server.Router -import org.http4s.blaze.server.BlazeServerBuilder +import sttp.tapir.perf import sttp.tapir.server.http4s.Http4sServerInterpreter object Vanilla { @@ -30,7 +31,7 @@ object Tapir { Router("/" -> { Http4sServerInterpreter[IO]().toRoutes( (0 to nRoutes) - .map((n: Int) => perfTests.Common.genTapirEndpoint(n).serverLogic(id => IO(((id + n).toString).asRight[String]))) + .map((n: Int) => Common.genTapirEndpoint(n).serverLogic(id => IO(((id + n).toString).asRight[String]))) .toList ) }) @@ -42,7 +43,7 @@ object Http4s { .bindHttp(8080, "localhost") .withHttpApp(router.orNotFound) .resource - .use(_ => { perfTests.Common.blockServer(); IO.pure(ExitCode.Success) }) + .use(_ => { perf.Common.blockServer(); IO.pure(ExitCode.Success) }) } } diff --git a/perf-tests/src/test/scala/Simulations.scala b/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala similarity index 97% rename from perf-tests/src/test/scala/Simulations.scala rename to perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala index 8cc1275d8b..71a9923bb8 100644 --- a/perf-tests/src/test/scala/Simulations.scala +++ b/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala @@ -1,4 +1,4 @@ -package perfTests +package sttp.tapir.perf import io.gatling.core.Predef._ import io.gatling.core.structure.{PopulationBuilder, ScenarioBuilder} From 984015777fbb65589abf306cf9a41468eb4ef705 Mon Sep 17 00:00:00 2001 From: adamw Date: Fri, 18 Mar 2022 09:18:58 +0100 Subject: [PATCH 4/7] Update gatling plugin --- build.sbt | 21 ++++++------ .../results/100users-5min-09-03-2022-ec2.md | 32 +++++++++---------- .../sttp/tapir/perf/{ => akka}/AkkaHttp.scala | 3 +- .../sttp/tapir/perf/{ => http4s}/Http4s.scala | 3 +- .../scala/sttp/tapir/perf/Simulations.scala | 2 +- project/plugins.sbt | 2 +- 6 files changed, 33 insertions(+), 30 deletions(-) rename perf-tests/src/main/scala/sttp/tapir/perf/{ => akka}/AkkaHttp.scala (96%) rename perf-tests/src/main/scala/sttp/tapir/perf/{ => http4s}/Http4s.scala (96%) diff --git a/build.sbt b/build.sbt index 3c74ab3c30..9865a11c43 100644 --- a/build.sbt +++ b/build.sbt @@ -5,6 +5,7 @@ import com.softwaremill.UpdateVersionInDocs import com.typesafe.tools.mima.core.{Problem, ProblemFilters} import sbt.Reference.display import sbt.internal.ProjectMatrix +import sbtassembly.AssemblyPlugin.autoImport.assembly // explicit import to avoid clash with gatling plugin import java.net.URL import scala.concurrent.duration.DurationInt @@ -357,8 +358,8 @@ val http4sVanillaMulti = taskKey[Unit]("http4s-vanilla-multi") val http4sTapirMulti = taskKey[Unit]("http4s-tapir-multi") def genPerfTestTask(servName: String, simName: String) = Def.taskDyn { Def.task { - (Compile / runMain).toTask(s" perfTests.${servName}Server").value - (Gatling / testOnly).toTask(s" perfTests.${simName}Simulation").value + (Compile / runMain).toTask(s" sttp.tapir.perf.${servName}Server").value + (Gatling / testOnly).toTask(s" sttp.tapir.perf.${simName}Simulation").value } } @@ -385,14 +386,14 @@ lazy val perfTests: ProjectMatrix = (projectMatrix in file("perf-tests")) fork := true, connectInput := true ) - .settings(akkaHttpVanilla := { (genPerfTestTask("AkkaHttp.Vanilla", "OneRoute")).value }) - .settings(akkaHttpTapir := { (genPerfTestTask("AkkaHttp.Tapir", "OneRoute")).value }) - .settings(akkaHttpVanillaMulti := { (genPerfTestTask("AkkaHttp.VanillaMulti", "MultiRoute")).value }) - .settings(akkaHttpTapirMulti := { (genPerfTestTask("AkkaHttp.TapirMulti", "MultiRoute")).value }) - .settings(http4sVanilla := { (genPerfTestTask("Http4s.Vanilla", "OneRoute")).value }) - .settings(http4sTapir := { (genPerfTestTask("Http4s.Tapir", "OneRoute")).value }) - .settings(http4sVanillaMulti := { (genPerfTestTask("Http4s.VanillaMulti", "MultiRoute")).value }) - .settings(http4sTapirMulti := { (genPerfTestTask("Http4s.TapirMulti", "MultiRoute")).value }) + .settings(akkaHttpVanilla := { (genPerfTestTask("akka.Vanilla", "OneRoute")).value }) + .settings(akkaHttpTapir := { (genPerfTestTask("akka.Tapir", "OneRoute")).value }) + .settings(akkaHttpVanillaMulti := { (genPerfTestTask("akka.VanillaMulti", "MultiRoute")).value }) + .settings(akkaHttpTapirMulti := { (genPerfTestTask("akka.TapirMulti", "MultiRoute")).value }) + .settings(http4sVanilla := { (genPerfTestTask("http4s.Vanilla", "OneRoute")).value }) + .settings(http4sTapir := { (genPerfTestTask("http4s.Tapir", "OneRoute")).value }) + .settings(http4sVanillaMulti := { (genPerfTestTask("http4s.VanillaMulti", "MultiRoute")).value }) + .settings(http4sTapirMulti := { (genPerfTestTask("http4s.TapirMulti", "MultiRoute")).value }) .jvmPlatform(scalaVersions = examplesScalaVersions) .dependsOn(core, akkaHttpServer, http4sServer) diff --git a/perf-tests/results/100users-5min-09-03-2022-ec2.md b/perf-tests/results/100users-5min-09-03-2022-ec2.md index 51d5eeaa67..59c9b4c041 100644 --- a/perf-tests/results/100users-5min-09-03-2022-ec2.md +++ b/perf-tests/results/100users-5min-09-03-2022-ec2.md @@ -11,17 +11,17 @@ Network communication through local IP on a shared EC2 network; ## Summary ``` Name : requests sent -[1] sttp.tapir.perf.TapirMultiServer : 568554 -[2] sttp.tapir.perf.TapirServer : 1310373 -[3] sttp.tapir.perf.VanillaMultiServer : 1301316 -[4] sttp.tapir.perf.VanillaServer : 1311758 -[5] sttp.tapir.perf.TapirMultiServer : 368887 -[6] sttp.tapir.perf.TapirServer : 788788 -[7] sttp.tapir.perf.VanillaMultiServer : 1074490 -[8] sttp.tapir.perf.VanillaServer : 1235687 +[1] sttp.tapir.perf.akka.TapirMultiServer : 568554 +[2] sttp.tapir.perf.akka.TapirServer : 1310373 +[3] sttp.tapir.perf.akka.VanillaMultiServer : 1301316 +[4] sttp.tapir.perf.akka.VanillaServer : 1311758 +[5] sttp.tapir.perf.akka.TapirMultiServer : 368887 +[6] sttp.tapir.perf.akka.TapirServer : 788788 +[7] sttp.tapir.perf.akka.VanillaMultiServer : 1074490 +[8] sttp.tapir.perf.akka.VanillaServer : 1235687 ``` ## Full results -### [1] sttp.tapir.perf.TapirMultiServer +### [1] sttp.tapir.perf.akka.TapirMultiServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -42,7 +42,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [2] sttp.tapir.perf.TapirServer +### [2] sttp.tapir.perf.akka.TapirServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -63,7 +63,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [3] sttp.tapir.perf.VanillaMultiServer +### [3] sttp.tapir.perf.akka.VanillaMultiServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -84,7 +84,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [4] sttp.tapir.perf.VanillaServer +### [4] sttp.tapir.perf.akka.VanillaServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -105,7 +105,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [5] sttp.tapir.perf.TapirMultiServer +### [5] sttp.tapir.perf.akka.TapirMultiServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -126,7 +126,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [6] sttp.tapir.perf.TapirServer +### [6] sttp.tapir.perf.akka.TapirServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -147,7 +147,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [7] sttp.tapir.perf.VanillaMultiServer +### [7] sttp.tapir.perf.akka.VanillaMultiServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- @@ -168,7 +168,7 @@ Network communication through local IP on a shared EC2 network; > failed 0 ( 0%) ================================================================================ ``` -### [8] sttp.tapir.perf.VanillaServer +### [8] sttp.tapir.perf.akka.VanillaServer ``` ================================================================================ ---- Global Information -------------------------------------------------------- diff --git a/perf-tests/src/main/scala/sttp/tapir/perf/AkkaHttp.scala b/perf-tests/src/main/scala/sttp/tapir/perf/akka/AkkaHttp.scala similarity index 96% rename from perf-tests/src/main/scala/sttp/tapir/perf/AkkaHttp.scala rename to perf-tests/src/main/scala/sttp/tapir/perf/akka/AkkaHttp.scala index b507c1c2ee..9760c0a9e6 100644 --- a/perf-tests/src/main/scala/sttp/tapir/perf/AkkaHttp.scala +++ b/perf-tests/src/main/scala/sttp/tapir/perf/akka/AkkaHttp.scala @@ -1,10 +1,11 @@ -package sttp.tapir.perf +package sttp.tapir.perf.akka import akka.actor.ActorSystem import akka.http.scaladsl.Http import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.Route import sttp.tapir.perf +import sttp.tapir.perf.Common import sttp.tapir.server.akkahttp.AkkaHttpServerInterpreter import scala.concurrent.{ExecutionContextExecutor, Future} diff --git a/perf-tests/src/main/scala/sttp/tapir/perf/Http4s.scala b/perf-tests/src/main/scala/sttp/tapir/perf/http4s/Http4s.scala similarity index 96% rename from perf-tests/src/main/scala/sttp/tapir/perf/Http4s.scala rename to perf-tests/src/main/scala/sttp/tapir/perf/http4s/Http4s.scala index 9087c5958d..588d30c846 100644 --- a/perf-tests/src/main/scala/sttp/tapir/perf/Http4s.scala +++ b/perf-tests/src/main/scala/sttp/tapir/perf/http4s/Http4s.scala @@ -1,4 +1,4 @@ -package sttp.tapir.perf +package sttp.tapir.perf.http4s import cats.effect._ import cats.effect.unsafe.implicits.global @@ -9,6 +9,7 @@ import org.http4s.dsl._ import org.http4s.implicits._ import org.http4s.server.Router import sttp.tapir.perf +import sttp.tapir.perf.Common import sttp.tapir.server.http4s.Http4sServerInterpreter object Vanilla { diff --git a/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala b/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala index 71a9923bb8..54ff628a14 100644 --- a/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala +++ b/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala @@ -7,7 +7,7 @@ import io.gatling.http.Predef._ import scala.concurrent.duration.DurationInt object CommonSimulations { - private val duration = 5.minutes + private val duration = 1.minute private val userCount = 100 private val baseUrl = "http://127.0.0.1:8080" diff --git a/project/plugins.sbt b/project/plugins.sbt index 64a6b62100..9e64076230 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -11,5 +11,5 @@ addSbtPlugin("org.jetbrains.scala" % "sbt-ide-settings" % "1.1.1") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.9.0") addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1") addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.2.0") -addSbtPlugin("io.gatling" % "gatling-sbt" % "3.2.2") +addSbtPlugin("io.gatling" % "gatling-sbt" % "4.1.3") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0") From 3b544ee140e4a553b74c2c5b401ed42ad1278fc4 Mon Sep 17 00:00:00 2001 From: adamw Date: Fri, 18 Mar 2022 09:41:51 +0100 Subject: [PATCH 5/7] Add warmup, simplify simulation --- .../scala/sttp/tapir/perf/Simulations.scala | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala b/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala index 54ff628a14..ed9d61928d 100644 --- a/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala +++ b/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala @@ -1,34 +1,31 @@ package sttp.tapir.perf import io.gatling.core.Predef._ -import io.gatling.core.structure.{PopulationBuilder, ScenarioBuilder} +import io.gatling.core.structure.PopulationBuilder import io.gatling.http.Predef._ -import scala.concurrent.duration.DurationInt +import scala.concurrent.duration.{Duration, DurationInt} object CommonSimulations { - private val duration = 1.minute private val userCount = 100 private val baseUrl = "http://127.0.0.1:8080" - val scn: ScenarioBuilder = scenario("get plaintext") - .during(duration.toSeconds.toInt) { - exec( - http("first plaintext") - .get("/4") - ) - } - - def genericInjection(n: Int): PopulationBuilder = { - val httpProtocol = http.baseUrl(baseUrl + "/path" + n.toString) - scn.inject(atOnceUsers(userCount)).protocols(httpProtocol) + def testScenario(warmupDuration: Duration, duration: Duration, routeNumber: Int): PopulationBuilder = { + val httpProtocol = http.baseUrl(baseUrl) + def execHttpGet(suffix: String) = exec(http(s"HTTP GET /path$routeNumber/4 $suffix").get(s"/path$routeNumber/4")) + scenario(s"Repeatedly invoke GET of route number $routeNumber") + .during(warmupDuration.toSeconds.toInt)(execHttpGet("warmup")) + .pause(5.seconds) + .during(duration.toSeconds.toInt)(execHttpGet("test")) + .inject(atOnceUsers(userCount)) + .protocols(httpProtocol) } } class OneRouteSimulation extends Simulation { - setUp(CommonSimulations.genericInjection(0)) + setUp(CommonSimulations.testScenario(10.seconds, 1.minute, 0)) } class MultiRouteSimulation extends Simulation { - setUp(CommonSimulations.genericInjection(127)) + setUp(CommonSimulations.testScenario(10.seconds, 1.minute, 127)) } From 802c300a289e88b7fe0736c6b9244a279b280bbe Mon Sep 17 00:00:00 2001 From: adamw Date: Fri, 18 Mar 2022 10:10:30 +0100 Subject: [PATCH 6/7] Remove warmup --- .../test/scala/sttp/tapir/perf/Simulations.scala | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala b/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala index ed9d61928d..fb4837b997 100644 --- a/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala +++ b/perf-tests/src/test/scala/sttp/tapir/perf/Simulations.scala @@ -4,28 +4,27 @@ import io.gatling.core.Predef._ import io.gatling.core.structure.PopulationBuilder import io.gatling.http.Predef._ -import scala.concurrent.duration.{Duration, DurationInt} +import scala.concurrent.duration.{DurationInt, FiniteDuration} object CommonSimulations { private val userCount = 100 private val baseUrl = "http://127.0.0.1:8080" - def testScenario(warmupDuration: Duration, duration: Duration, routeNumber: Int): PopulationBuilder = { + def testScenario(duration: FiniteDuration, routeNumber: Int): PopulationBuilder = { val httpProtocol = http.baseUrl(baseUrl) - def execHttpGet(suffix: String) = exec(http(s"HTTP GET /path$routeNumber/4 $suffix").get(s"/path$routeNumber/4")) + val execHttpGet = exec(http(s"HTTP GET /path$routeNumber/4").get(s"/path$routeNumber/4")) + scenario(s"Repeatedly invoke GET of route number $routeNumber") - .during(warmupDuration.toSeconds.toInt)(execHttpGet("warmup")) - .pause(5.seconds) - .during(duration.toSeconds.toInt)(execHttpGet("test")) + .during(duration.toSeconds.toInt)(execHttpGet) .inject(atOnceUsers(userCount)) .protocols(httpProtocol) } } class OneRouteSimulation extends Simulation { - setUp(CommonSimulations.testScenario(10.seconds, 1.minute, 0)) + setUp(CommonSimulations.testScenario(1.minute, 0)) } class MultiRouteSimulation extends Simulation { - setUp(CommonSimulations.testScenario(10.seconds, 1.minute, 127)) + setUp(CommonSimulations.testScenario(1.minute, 127)) } From fba01b9943b47446910f0db745e555e0e72f8e60 Mon Sep 17 00:00:00 2001 From: adamw Date: Fri, 18 Mar 2022 10:58:03 +0100 Subject: [PATCH 7/7] Readme --- perf-tests/README.md | 14 +++++++++----- .../100users-1min-18-03-2022-local-adamw.md | 8 ++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 perf-tests/results/100users-1min-18-03-2022-local-adamw.md diff --git a/perf-tests/README.md b/perf-tests/README.md index 5bab44a635..0103ab3fca 100644 --- a/perf-tests/README.md +++ b/perf-tests/README.md @@ -1,15 +1,19 @@ # seperate testing -To start a server, run `perfTests/run` and select the server you want to test. +To start a server, run `perfTests/run` and select the server you want to test, or in a single command: -To test vanilla akka-http load, run this command: ``` -perfTests / Gatling / testOnly perfTests.AkkaHttpVanillaSimulation +sbt "perfTests/runMain sttp.tapir.perf.akka.VanillaMultiServer" +// or +sbt "perfTests/runMain sttp.tapir.perf.akka.TapirMultiServer" +// or others ... ``` -To test tapir with akka-http load, run this command: +Then run the test: ``` -perfTests / Gatling / testOnly perfTests.AkkaHttpTapirSimulation +sbt "perfTests/Gatling/testOnly sttp.tapir.perf.OneRouteSimulation" +// or +sbt "perfTests/Gatling/testOnly sttp.tapir.perf.MultiRouteSimulation" ``` This method yields the most performant results, but requires running the commands in two seperate sbt instacnes. diff --git a/perf-tests/results/100users-1min-18-03-2022-local-adamw.md b/perf-tests/results/100users-1min-18-03-2022-local-adamw.md new file mode 100644 index 0000000000..37df1fe612 --- /dev/null +++ b/perf-tests/results/100users-1min-18-03-2022-local-adamw.md @@ -0,0 +1,8 @@ +# Setup + +2019 mbp, 2,3 GHz 8-Core Intel Core i9 + +# Results + +* vanilla akka-http, multi-route: 23278 req/s +* tapir akka-http, multi-route: 8277 req/s \ No newline at end of file