Browse Source

Update Finagle and Finch benchmarks (#2518)

Vladimir Kostyukov 8 years ago
parent
commit
b4746cdbc9

+ 2 - 2
frameworks/Scala/finagle/build.sbt

@@ -2,11 +2,11 @@ name := "finagle"
 
 
 scalaVersion := "2.11.8"
 scalaVersion := "2.11.8"
 
 
-version := "1.0.2"
+version := "1.0.3"
 
 
 com.github.retronym.SbtOneJar.oneJarSettings
 com.github.retronym.SbtOneJar.oneJarSettings
 
 
 libraryDependencies ++= Seq(
 libraryDependencies ++= Seq(
-  "com.twitter" %% "finagle-http" % "6.36.0",
+  "com.twitter" %% "finagle-http" % "6.41.0",
   "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.5.3"
   "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.5.3"
 )
 )

+ 2 - 4
frameworks/Scala/finagle/src/main/scala/Main.scala

@@ -1,5 +1,3 @@
-import java.util.Date
-
 import com.fasterxml.jackson.databind.ObjectMapper
 import com.fasterxml.jackson.databind.ObjectMapper
 import com.fasterxml.jackson.module.scala.DefaultScalaModule
 import com.fasterxml.jackson.module.scala.DefaultScalaModule
 import com.twitter.finagle.{Service, SimpleFilter, Http}
 import com.twitter.finagle.{Service, SimpleFilter, Http}
@@ -34,8 +32,8 @@ object Main extends App {
   val serverAndDate: SimpleFilter[Request, Response] = new SimpleFilter[Request, Response] {
   val serverAndDate: SimpleFilter[Request, Response] = new SimpleFilter[Request, Response] {
 
 
     private[this] val addServerAndDate: Response => Response = { rep =>
     private[this] val addServerAndDate: Response => Response = { rep =>
-        rep.server = "Finagle"
-        rep.date = new Date()
+        rep.headerMap.set("Server", "Finagle")
+        rep.headerMap.set("Date", currentTime())
 
 
         rep
         rep
     }
     }

+ 18 - 0
frameworks/Scala/finagle/src/main/scala/currentTime.scala

@@ -0,0 +1,18 @@
+import java.time.format.DateTimeFormatter
+import java.time.{Instant, ZoneOffset}
+
+object currentTime {
+  private[this] val formatter: DateTimeFormatter = 
+    DateTimeFormatter.RFC_1123_DATE_TIME.withZone(ZoneOffset.UTC)
+
+  @volatile private[this] var last: (Long, String) = (0, "")
+
+  def apply(): String = {
+    val time = System.currentTimeMillis()
+    if (time - last._1 > 1000) {
+      last = time -> formatter.format(Instant.ofEpochMilli(time))
+    }
+
+    last._2
+  }
+}

+ 4 - 9
frameworks/Scala/finch/build.sbt

@@ -1,18 +1,13 @@
 name := """techempower-benchmarks-finch"""
 name := """techempower-benchmarks-finch"""
 
 
-version := "0.0.4"
+version := "0.0.5"
 
 
 scalaVersion := "2.11.8"
 scalaVersion := "2.11.8"
 
 
 com.github.retronym.SbtOneJar.oneJarSettings
 com.github.retronym.SbtOneJar.oneJarSettings
 
 
 libraryDependencies ++= Seq(
 libraryDependencies ++= Seq(
-  "com.twitter" %% "finagle-http" % "6.36.0",
-  "com.github.finagle" %% "finch-core" % "0.11.0-M2",
-  "com.github.finagle" %% "finch-circe" % "0.11.0-M2",
-  "io.circe" %% "circe-core" % "0.5.0-M2",
-  "io.circe" %% "circe-generic" % "0.5.0-M2",
-  "io.circe" %% "circe-jawn" % "0.5.0-M2"
+  "com.github.finagle" %% "finch-core" % "0.12.0",
+  "com.github.finagle" %% "finch-circe" % "0.12.0",
+  "io.circe" %% "circe-generic" % "0.7.0"
 )
 )
-
-resolvers += Resolver.sonatypeRepo("snapshots")

+ 3 - 9
frameworks/Scala/finch/src/main/scala/Main.scala

@@ -1,6 +1,3 @@
-import java.time.format.DateTimeFormatter
-import java.time.{Instant, ZoneOffset}
-
 import com.twitter.io.Buf
 import com.twitter.io.Buf
 import com.twitter.finagle.http.Response
 import com.twitter.finagle.http.Response
 import com.twitter.finagle.Http
 import com.twitter.finagle.Http
@@ -14,15 +11,12 @@ import io.finch.circe._
 
 
 object Main extends App {
 object Main extends App {
 
 
-  val timeFormatter: DateTimeFormatter = 
-    DateTimeFormatter.RFC_1123_DATE_TIME.withZone(ZoneOffset.UTC)
-
   val helloWorld: Buf = Buf.Utf8("Hello, World!")
   val helloWorld: Buf = Buf.Utf8("Hello, World!")
 
 
   val json: Endpoint[Json] = get("json") {
   val json: Endpoint[Json] = get("json") {
     Ok(Json.obj("message" -> Json.fromString("Hello, World!")))
     Ok(Json.obj("message" -> Json.fromString("Hello, World!")))
       .withHeader("Server" -> "Finch")
       .withHeader("Server" -> "Finch")
-      .withHeader("Date" -> timeFormatter.format(Instant.now()))
+      .withHeader("Date" -> currentTime())
   }
   }
 
 
   // Downgrade a text/plain endpoint to `Endpoint[Response]` as per
   // Downgrade a text/plain endpoint to `Endpoint[Response]` as per
@@ -32,9 +26,9 @@ object Main extends App {
     rep.content = helloWorld
     rep.content = helloWorld
     rep.contentType = "text/plain"
     rep.contentType = "text/plain"
     rep.headerMap.set("Server", "Finch")
     rep.headerMap.set("Server", "Finch")
-    rep.headerMap.set("Date", timeFormatter.format(Instant.now()))
+    rep.headerMap.set("Date", currentTime())
 
 
-    Ok(rep)
+    rep
   }
   }
 
 
   Await.ready(Http.server
   Await.ready(Http.server

+ 18 - 0
frameworks/Scala/finch/src/main/scala/currentTime.scala

@@ -0,0 +1,18 @@
+import java.time.format.DateTimeFormatter
+import java.time.{Instant, ZoneOffset}
+
+object currentTime {
+  private[this] val formatter: DateTimeFormatter = 
+    DateTimeFormatter.RFC_1123_DATE_TIME.withZone(ZoneOffset.UTC)
+
+  @volatile private[this] var last: (Long, String) = (0, "")
+
+  def apply(): String = {
+    val time = System.currentTimeMillis()
+    if (time - last._1 > 1000) {
+      last = time -> formatter.format(Instant.ofEpochMilli(time))
+    }
+
+    last._2
+  }
+}