Răsfoiți Sursa

akka-http: use latest version and optimized settings (#7244)

Johannes Rudolph 3 ani în urmă
părinte
comite
53d2922fa5

+ 1 - 1
frameworks/Scala/akka-http/akka-http.dockerfile

@@ -23,4 +23,4 @@ RUN sbt clean compile stage
 
 EXPOSE 9000
 
-CMD ["target/universal/stage/bin/akka-http-benchmark", "-Dakka.http.benchmark.mysql.dbhost=tfb-database", "-J-server", "-J-Xms2g", "-J-Xmx2g", "-J-XX:NewSize=1g", "-J-XX:MaxNewSize=1g", "-J-XX:InitialCodeCacheSize=256m", "-J-XX:ReservedCodeCacheSize=256m", "-J-XX:+UseParallelGC", "-J-XX:-UseBiasedLocking", "-J-XX:+AlwaysPreTouch"]
+CMD ["target/universal/stage/bin/akka-http-benchmark", "-Dakka.http.benchmark.mysql.dbhost=tfb-database", "-J-server", "-J-Xms2g", "-J-Xmx2g", "-J-XX:NewSize=1g", "-J-XX:MaxNewSize=1g", "-J-XX:InitialCodeCacheSize=256m", "-J-XX:ReservedCodeCacheSize=256m", "-J-XX:+UseParallelGC", "-J-XX:-UseBiasedLocking", "-J-XX:+AlwaysPreTouch", "-J-XX:+UseNUMA", "-J-XX:+AggressiveOpts"]

+ 8 - 4
frameworks/Scala/akka-http/akka-http/build.sbt

@@ -6,13 +6,17 @@ name := "akka-http-benchmark"
 
 version := "0.1.0-SNAPSHOT"
 
-scalaVersion := "2.13.6"
+scalaVersion := "2.13.8"
 
-resolvers += "Akka Snapshot Repository" at "http://repo.akka.io/snapshots/"
+val akkaV = "2.6.19"
+val akkaHttpV = "10.2.9"
+
+// to get latest versions
+resolvers += "akka-http-snapshot-repository" at "https://oss.sonatype.org/content/repositories/snapshots"
 
 libraryDependencies ++= Seq(
-  "com.typesafe.akka" %% "akka-http" % "10.2.6",
-  "com.typesafe.akka" %% "akka-stream" % "2.6.16",
+  "com.typesafe.akka" %% "akka-http" % akkaHttpV,
+  "com.typesafe.akka" %% "akka-stream" % akkaV,
   "de.heikoseeberger" %% "akka-http-jsoniter-scala" % "1.34.0",
   "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.6.0",
   "mysql" % "mysql-connector-java" % "8.0.21",

+ 1 - 1
frameworks/Scala/akka-http/akka-http/project/build.properties

@@ -1 +1 @@
-sbt.version=1.3.13
+sbt.version=1.5.4

+ 3 - 1
frameworks/Scala/akka-http/akka-http/project/plugins.sbt

@@ -4,4 +4,6 @@ classpathTypes += "maven-plugin"
 
 addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.2")
 addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.16")
-addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.3")
+addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.3")
+
+addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")

+ 4 - 1
frameworks/Scala/akka-http/akka-http/src/main/resources/application.conf

@@ -6,9 +6,11 @@ akka {
         parallelism-max = 64   # --
         parallelism-factor = 1 # one thread per core is enough
       }
-      throughput = 64
     }
+    internal-dispatcher = "akka.actor.default-dispatcher"
   }
+  stream.materializer.io.tcp.write-buffer-size = 128k
+  stream.materializer.io.tcp.coalesce-writes = 1
   http {
     benchmark {
       host: 0.0.0.0
@@ -25,6 +27,7 @@ akka {
     }
     server {
       backlog = 1024
+      request-timeout = off
     }
   }
 }

+ 1 - 1
frameworks/Scala/akka-http/akka-http/src/main/scala/com/typesafe/akka/http/benchmark/App.scala

@@ -10,7 +10,7 @@ import org.fusesource.scalate.TemplateEngine
 
 import scala.concurrent.ExecutionContext
 
-class App extends Infrastructure with RandomGenerator with MySqlDataStore with PlaintextHandler with JsonHandler with DbHandler
+class App extends Infrastructure with RandomGenerator with MySqlDataStore with JsonHandler with DbHandler
   with QueriesHandler with FortunesHandler with UpdatesHandler with RequestMapping with BenchmarkBootstrap with Templating {
 
   val templateEngine = new TemplateEngine()

+ 12 - 1
frameworks/Scala/akka-http/akka-http/src/main/scala/com/typesafe/akka/http/benchmark/Bootstrap.scala

@@ -1,6 +1,10 @@
 package com.typesafe.akka.http.benchmark
 
 import akka.http.scaladsl.Http
+import akka.http.scaladsl.model._
+import akka.http.scaladsl.util.FastFuture
+
+import scala.concurrent.Future
 
 trait Bootstrap {
   def run(): Unit
@@ -12,5 +16,12 @@ trait BenchmarkBootstrap extends Bootstrap { _: Infrastructure with RequestMappi
       appConfig.getString("akka.http.benchmark.host"),
       appConfig.getInt("akka.http.benchmark.port"))
       .adaptSettings(settings => settings.mapHttp2Settings(_.withMaxConcurrentStreams(16)))
-      .bind(asRoute)
+      .bind(handler)
+
+  val plainTextResponse = FastFuture.successful(HttpResponse(entity = HttpEntity("Hello, World!")))
+  lazy val mainHandler: HttpRequest => Future[HttpResponse] = asRoute
+  lazy val handler: HttpRequest => Future[HttpResponse] = {
+    case HttpRequest(HttpMethods.GET, Uri.Path("/plaintext"), _, _, _) => plainTextResponse
+    case x => mainHandler(x)
+  }
 }

+ 2 - 2
frameworks/Scala/akka-http/akka-http/src/main/scala/com/typesafe/akka/http/benchmark/RequestMapping.scala

@@ -4,7 +4,7 @@ import akka.http.scaladsl.server.Directives._
 import akka.http.scaladsl.server.Route
 import com.typesafe.akka.http.benchmark.handlers._
 
-trait RequestMapping { _: PlaintextHandler with JsonHandler with DbHandler with QueriesHandler with FortunesHandler with UpdatesHandler =>
+trait RequestMapping { _: JsonHandler with DbHandler with QueriesHandler with FortunesHandler with UpdatesHandler =>
   def asRoute: Route =
-    plainTextEndpoint ~ jsonEndpoint ~ dbEndpoint ~ queriesEndpoint ~ fortunesEndpoint ~ updatesEndpoint
+    jsonEndpoint ~ dbEndpoint ~ queriesEndpoint ~ fortunesEndpoint ~ updatesEndpoint
 }

+ 0 - 20
frameworks/Scala/akka-http/akka-http/src/main/scala/com/typesafe/akka/http/benchmark/handlers/PlaintextHandler.scala

@@ -1,20 +0,0 @@
-package com.typesafe.akka.http.benchmark.handlers
-
-import akka.http.scaladsl.model.HttpCharsets._
-import akka.http.scaladsl.model.HttpEntity
-import akka.http.scaladsl.model.HttpResponse
-import akka.http.scaladsl.model.MediaType
-import akka.http.scaladsl.server.Directives._
-import akka.http.scaladsl.server.Route
-
-trait PlaintextHandler {
-  // akka-http will always generate a charset parameter for text/plain, so to be competitive, we create a custom
-  // one here to save a few bytes of headers for this particular test case. This is explicitly allowed in:
-  // https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview#specific-test-requirements
-  val plainTextResponse = HttpResponse(entity = HttpEntity(MediaType.customWithFixedCharset("text", "plain", `UTF-8`), "Hello, World!"))
-
-  def plainTextEndpoint: Route =
-    (get & path("plaintext")) {
-      complete(plainTextResponse)
-    }
-}