Browse Source

Fintrospect: Upgrade to lib version, and tweak JVM parameters (#2264)

David Denton 9 years ago
parent
commit
3a2f558cf6

+ 2 - 2
frameworks/Scala/fintrospect/README.md

@@ -4,8 +4,8 @@
 The tests were run with:
 The tests were run with:
 
 
 * [Java Oracle 1.8.0_25](http://www.oracle.com/technetwork/java/javase)
 * [Java Oracle 1.8.0_25](http://www.oracle.com/technetwork/java/javase)
-* [fintrospect 12.4.0](https://github.com/daviddenton/fintrospect)
-* [finagle 6.33.0](https://github.com/twitter/finagle)
+* [fintrospect 13.5.2](https://github.com/daviddenton/fintrospect)
+* [finagle 6.36.0](https://github.com/twitter/finagle)
 
 
 ## Test URLs
 ## Test URLs
 
 

+ 23 - 20
frameworks/Scala/fintrospect/benchmark_config.json

@@ -1,23 +1,26 @@
 {
 {
   "framework": "fintrospect",
   "framework": "fintrospect",
-  "tests": [{
-    "default": {
-      "orm": "Raw",
-      "database_os": "Linux",
-      "setup_file": "setup",
-      "json_url": "/json",
-      "plaintext_url": "/plaintext",
-      "port": 9000,
-      "approach": "Realistic",
-      "classification": "Micro",
-      "database": "None",
-      "framework": "fintrospect",
-      "language": "Scala",
-      "platform": "Netty",
-      "webserver": "None",
-      "os": "Linux",
-      "display_name": "fintrospect",
-      "notes": ""
+  "tests": [
+    {
+      "default": {
+        "orm": "Raw",
+        "database_os": "Linux",
+        "setup_file": "setup",
+        "json_url": "/json",
+        "plaintext_url": "/plaintext",
+        "port": 9000,
+        "approach": "Realistic",
+        "classification": "Micro",
+        "database": "None",
+        "framework": "fintrospect",
+        "language": "Scala",
+        "platform": "Netty",
+        "webserver": "None",
+        "os": "Linux",
+        "display_name": "fintrospect",
+        "notes": "",
+        "versus": "finagle"
+      }
     }
     }
-  }]
-}
+  ]
+}

+ 6 - 4
frameworks/Scala/fintrospect/build.sbt

@@ -1,6 +1,6 @@
 name := """techempower-benchmarks-fintrospect"""
 name := """techempower-benchmarks-fintrospect"""
 
 
-version := "0.0.4"
+version := "0.0.6"
 
 
 scalaVersion := "2.11.8"
 scalaVersion := "2.11.8"
 
 
@@ -15,8 +15,10 @@ com.github.retronym.SbtOneJar.oneJarSettings
 mainClass in(Compile, run) := Some("FintrospectBenchmarkServer")
 mainClass in(Compile, run) := Some("FintrospectBenchmarkServer")
 
 
 libraryDependencies ++= Seq(
 libraryDependencies ++= Seq(
-  "io.fintrospect" %% "fintrospect-core" % "13.3.0",
-  "io.fintrospect" %% "fintrospect-circe" % "13.3.0"
-)
+  "io.fintrospect" %% "fintrospect-core" % "13.7.0",
+  "io.fintrospect" %% "fintrospect-circe" % "13.7.0",
+  "io.fintrospect" %% "fintrospect-mustache" % "13.7.0",
+  "com.twitter" %% "finagle-mysql" % "6.37.0"
+  )
 
 
 resolvers += Resolver.sonatypeRepo("snapshots")
 resolvers += Resolver.sonatypeRepo("snapshots")

+ 1 - 1
frameworks/Scala/fintrospect/setup.sh

@@ -4,4 +4,4 @@ fw_depends java sbt
 
 
 sbt 'oneJar' -batch
 sbt 'oneJar' -batch
 
 
-java -jar target/scala-2.11/*fintrospect*one-jar.jar &
+java -server -XX:+UseNUMA -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+AlwaysPreTouch -jar target/scala-2.11/*fintrospect*one-jar.jar &

+ 3 - 0
frameworks/Scala/fintrospect/source_code

@@ -1,2 +1,5 @@
 fintrospect/src/main/scala/
 fintrospect/src/main/scala/
+fintrospect/src/main/scala/Fortunes.scala
+fintrospect/src/main/scala/JsonHelloWorld.scala
+fintrospect/src/main/scala/PlainTextHelloWorld.scala
 fintrospect/src/main/scala/FintrospectBenchmarkServer.scala
 fintrospect/src/main/scala/FintrospectBenchmarkServer.scala

+ 1 - 0
frameworks/Scala/fintrospect/src/main/resources/FortunesList.mustache

@@ -0,0 +1 @@
+<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>{{#items}}<tr><td>{{id}}</td><td>{{message}}</td></tr>{{/items}}</table></body></html>

+ 16 - 22
frameworks/Scala/fintrospect/src/main/scala/FintrospectBenchmarkServer.scala

@@ -1,42 +1,36 @@
 import java.time.ZonedDateTime._
 import java.time.ZonedDateTime._
 import java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME
 import java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME
 
 
-import com.twitter.finagle.http.Method.Get
-import com.twitter.finagle.http.Request
-import com.twitter.finagle.http.Status._
 import com.twitter.finagle.http.path.Root
 import com.twitter.finagle.http.path.Root
+import com.twitter.finagle.http.{Request, Response}
 import com.twitter.finagle.stats.NullStatsReceiver
 import com.twitter.finagle.stats.NullStatsReceiver
 import com.twitter.finagle.tracing.NullTracer
 import com.twitter.finagle.tracing.NullTracer
-import com.twitter.finagle.{Http, Service}
-import com.twitter.util.Await
-import io.fintrospect.formats.json.Circe.JsonFormat._
-import io.fintrospect.{ModuleSpec, RouteSpec}
+import com.twitter.finagle.{Filter, Http}
+import com.twitter.util.{Await, NullMonitor}
+import io.fintrospect.ModuleSpec
+import io.fintrospect.renderers.simplejson.SimpleJson
 
 
 object FintrospectBenchmarkServer extends App {
 object FintrospectBenchmarkServer extends App {
 
 
-  val plainTextHelloWorld = {
-    import io.fintrospect.formats.PlainText.ResponseBuilder.implicits._
-    Service.mk { r: Request => Ok("Hello, World!")
-      .withHeaders("Server" -> "Example", "Date" -> RFC_1123_DATE_TIME.format(now()))
-    }
+  val addServerAndDate = Filter.mk[Request, Response, Request, Response] { (req, svc) =>
+    svc(req).map(resp => {
+      resp.headerMap("Server") = "Example"
+      resp.headerMap("Date") = RFC_1123_DATE_TIME.format(now())
+      resp
+    })
   }
   }
 
 
-  val jsonHelloWorld = {
-    import io.fintrospect.formats.json.Circe.ResponseBuilder.implicits._
-    Service.mk { r: Request => Ok(obj("message" -> string("Hello, World!")))
-      .withHeaders("Server" -> "Example", "Date" -> RFC_1123_DATE_TIME.format(now()))
-    }
-  }
-
-  val module = ModuleSpec(Root)
-    .withRoute(RouteSpec().at(Get) / "plaintext" bindTo plainTextHelloWorld)
-    .withRoute(RouteSpec().at(Get) / "json" bindTo jsonHelloWorld)
+  val module = ModuleSpec(Root, SimpleJson(), addServerAndDate)
+    .withRoute(JsonHelloWorld.route)
+    .withRoute(PlainTextHelloWorld.route)
+    .withRoute(Fortunes.route)
 
 
   Await.ready(
   Await.ready(
     Http.server
     Http.server
       .withCompressionLevel(0)
       .withCompressionLevel(0)
       .withStatsReceiver(NullStatsReceiver)
       .withStatsReceiver(NullStatsReceiver)
       .withTracer(NullTracer)
       .withTracer(NullTracer)
+      .withMonitor(NullMonitor)
       .serve(":9000", module.toService)
       .serve(":9000", module.toService)
   )
   )
 }
 }

+ 52 - 0
frameworks/Scala/fintrospect/src/main/scala/Fortunes.scala

@@ -0,0 +1,52 @@
+import com.twitter.finagle.client.DefaultPool.Param
+import com.twitter.finagle.http.Method.Get
+import com.twitter.finagle.http.Request
+import com.twitter.finagle.mysql.{IntValue, Result, ResultSet, StringValue}
+import com.twitter.finagle.stats.NullStatsReceiver
+import com.twitter.finagle.tracing.NullTracer
+import com.twitter.finagle.{Mysql, Service}
+import com.twitter.util.Duration.fromSeconds
+import com.twitter.util.NullMonitor
+import io.fintrospect.RouteSpec
+import io.fintrospect.formats.Html
+import io.fintrospect.templating.MustacheTemplates.CachingClasspath
+import io.fintrospect.templating.{RenderView, View}
+
+case class Fortune(id: Int, message: String)
+
+case class FortunesList(items: Seq[Fortune]) extends View
+
+object Fortunes {
+  private val toFortunes: PartialFunction[Result, Seq[Fortune]] = {
+    case rs: ResultSet => rs.rows
+      .map(row => {
+        val IntValue(id) = row("id").get
+        val StringValue(message) = row("message").get
+        Fortune(id, message)
+      })
+    case _ => Seq.empty
+  }
+
+  private val dbClient = Mysql.client
+    .withCredentials("benchmarkdbuser", "benchmarkdbpass")
+    .withDatabase("hello_world")
+    .configured(Param(low = 0, high = 10, idleTime = fromSeconds(5 * 60), bufferSize = 0, maxWaiters = Int.MaxValue))
+    .withStatsReceiver(NullStatsReceiver)
+    .withMonitor(NullMonitor)
+    .withTracer(NullTracer)
+    .withMaxConcurrentPrepareStatements(256)
+    .newRichClient("localhost:3306")
+
+  private val statement = dbClient.prepare("SELECT * FROM Fortune")
+
+  private val service = new RenderView(Html.ResponseBuilder, CachingClasspath()).andThen(
+    Service.mk {
+      r: Request =>
+        statement().map(toFortunes).map(f => {
+          val sortedFortunes = (Fortune(-1, "Additional fortune added at request time.") +: f).sortBy(_.message)
+          FortunesList(sortedFortunes)
+        })
+    })
+
+  val route = RouteSpec().at(Get) / "fortunes" bindTo Fortunes.service
+}

+ 14 - 0
frameworks/Scala/fintrospect/src/main/scala/JsonHelloWorld.scala

@@ -0,0 +1,14 @@
+import com.twitter.finagle.Service
+import com.twitter.finagle.http.Method.Get
+import com.twitter.finagle.http.Request
+import com.twitter.finagle.http.Status.Ok
+import io.fintrospect.RouteSpec
+import io.fintrospect.formats.json.Circe.JsonFormat.{obj, string}
+import io.fintrospect.formats.json.Circe.ResponseBuilder.implicits._
+
+object JsonHelloWorld {
+
+  private val service = Service.mk { r: Request => Ok(obj("message" -> string("Hello, World!"))) }
+
+  val route = RouteSpec().at(Get) / "json" bindTo JsonHelloWorld.service
+}

+ 16 - 0
frameworks/Scala/fintrospect/src/main/scala/PlainTextHelloWorld.scala

@@ -0,0 +1,16 @@
+import com.twitter.finagle.Service
+import com.twitter.finagle.http.Method.Get
+import com.twitter.finagle.http.Request
+import com.twitter.finagle.http.Status.Ok
+import com.twitter.io.Buf
+import io.fintrospect.RouteSpec
+import io.fintrospect.formats.PlainText.ResponseBuilder.implicits._
+
+object PlainTextHelloWorld {
+
+  private val preallocatedMsgForPlainText = Buf.Utf8("Hello, World!")
+
+  private val service = Service.mk { r: Request => Ok(preallocatedMsgForPlainText) }
+
+  val route = RouteSpec().at(Get) / "plaintext" bindTo service
+}