Browse Source

feat(zio-http): add plaintext and json benchmarks for zio-http (#6447)

* feat(zio-http): add plaintext and json benchmarks for zio-http

* build(zio-http): update benchmark source code

* fix(zio-http): Json encoding should be done on each response

* fix(zio-http): remove unnecessary jvm options

* build(zio-http): cleanup dockerfile

* build(zio-http): cleanup dockerfile

* style(zio-http): scalafmt

* fix(zio-http): update zhttp version and change example
Amit Kumar Singh 4 years ago
parent
commit
3197c74e19

+ 22 - 0
frameworks/Scala/zio-http/README.md

@@ -0,0 +1,22 @@
+# ZIO-HTTP Benchmarking Test
+
+This is the ZIO Http portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
+
+### Test Type Implementation Source Code
+
+* [JSON](src/main/scala/Main.scala)
+* [PLAINTEXT](src/main/scala/Main.scala)
+
+## Versions
+
+* [Java OpenJDK 11](https://openjdk.java.net/)
+
+## Test URLs
+
+### JSON
+
+http://localhost:8080/json
+
+### PLAINTEXT
+
+http://localhost:8080/plaintext

+ 26 - 0
frameworks/Scala/zio-http/benchmark_config.json

@@ -0,0 +1,26 @@
+{
+  "framework": "zio-http",
+  "tests": [
+    {
+      "default": {
+        "plaintext_url": "/plaintext",
+        "json_url": "/json",
+        "port": 8080,
+        "database": "None",
+        "approach": "Realistic",
+        "classification": "Micro",
+        "framework": "zio-http",
+        "language": "Scala",
+        "flavor": "None",
+        "orm": "Raw",
+        "platform": "Netty",
+        "webserver": "None",
+        "database_os": "Linux",
+        "os": "Linux",
+        "display_name": "zio-http",
+        "notes": "",
+        "versus": "None"
+      }
+    }
+  ]
+}

+ 15 - 0
frameworks/Scala/zio-http/build.sbt

@@ -0,0 +1,15 @@
+name := "zio-http"
+
+version := "1.0.0"
+scalaVersion := "2.13.3"
+lazy val root = (project in file("."))
+  .settings(
+    name := "helloExample",
+    libraryDependencies ++=
+      Seq(
+        "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core"   % "2.6.4",
+        "com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % "2.6.4" % "compile-internal",
+        "io.d11"                                 % "zhttp"                 % "1.0.0-RC3.1",
+      ),
+    testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
+  )

+ 15 - 0
frameworks/Scala/zio-http/config.toml

@@ -0,0 +1,15 @@
+[framework]
+name = "zio-http"
+
+[main]
+urls.plaintext = "/plaintext"
+urls.json = "/json"
+approach = "Realistic"
+classification = "Micro"
+database = "None"
+database_os = "Linux"
+os = "Linux"
+orm = "Raw"
+platform = "Netty"
+webserver = "None"
+versus = "None"

+ 1 - 0
frameworks/Scala/zio-http/project/build.properties

@@ -0,0 +1 @@
+sbt.version = 1.4.7

+ 1 - 0
frameworks/Scala/zio-http/project/plugins.sbt

@@ -0,0 +1 @@
+addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")

+ 22 - 0
frameworks/Scala/zio-http/src/main/scala/Main.scala

@@ -0,0 +1,22 @@
+import zhttp.http._
+import zhttp.service.Server
+import zio.{App, ExitCode, URIO}
+import com.github.plokhotnyuk.jsoniter_scala.macros._
+import com.github.plokhotnyuk.jsoniter_scala.core._
+import java.time.ZonedDateTime
+import java.time.format.DateTimeFormatter
+
+object WebApp extends App {
+  val message: String                         = "Hello, World!"
+  def createDate: String                      = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now)
+  case class Message(message: String)
+  implicit val codec: JsonValueCodec[Message] = JsonCodecMaker.make
+
+  val app = Http.collect[Request] {
+    case Method.GET -> Root / "plaintext" => Response.text(message)
+    case Method.GET -> Root / "json"      => Response.jsonString(writeToString(Message(message)))
+  }
+
+  override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = Server.start(8080, app).exitCode
+
+}

+ 20 - 0
frameworks/Scala/zio-http/zio-http.dockerfile

@@ -0,0 +1,20 @@
+FROM openjdk:11-jdk
+
+ARG SBT_VERSION=1.2.8
+
+RUN \
+  curl -L -o sbt-$SBT_VERSION.deb https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb && \
+  dpkg -i sbt-$SBT_VERSION.deb && \
+  rm sbt-$SBT_VERSION.deb && \
+  apt-get update && \
+  apt-get install sbt && \
+  sbt sbtVersion
+
+WORKDIR /zhttp
+COPY src src
+COPY project project
+COPY build.sbt build.sbt
+RUN sbt assembly
+
+EXPOSE 8080
+CMD java -Xms2G -Xmx2G -server -jar /zhttp/target/scala-2.13/zio-http-assembly-1.0.0.jar