Browse Source

Update http4s (#6964)

* Move existing solution in blaze folder

* Bump http4s/blaze deps

* Update jdk to 17

* Align jvm opts with akka-http

* Bump cats-effects, fs2

* Update README.md

* Cleanup
Alessandro Zoffoli 3 years ago
parent
commit
f5f52a1b2a

+ 3 - 3
frameworks/Scala/http4s/README.md

@@ -3,6 +3,6 @@
 ## Infrastructure Software Versions
 
 The tests were run with:
-* [OpenJDK](https://hub.docker.com/_/openjdk) 8 for building and the latest alpine for running, as per the [Scala JDK Compatibility page](https://docs.scala-lang.org/overviews/jdk-compatibility/overview.html)
-* [http4s 0.21.3](http://http4s.org/)
-* [doobie 0.8.8](https://tpolecat.github.io/doobie/)
+* [OpenJDK](https://hub.docker.com/_/openjdk) 17, the latest LTS release, as per the [Scala JDK Compatibility page](https://docs.scala-lang.org/overviews/jdk-compatibility/overview.html)
+* [http4s 0.23.6](http://http4s.org/)
+* [cats-effets 3.3.0](https://typelevel.org/cats-effect/)

+ 6 - 5
frameworks/Scala/http4s/build.sbt → frameworks/Scala/http4s/blaze/build.sbt

@@ -2,7 +2,7 @@ name := "http4s"
 
 version := "1.0"
 
-scalaVersion := "2.13.6"
+scalaVersion := "2.13.7"
 
 scalacOptions ++= Seq(
   "-deprecation",
@@ -13,12 +13,13 @@ scalacOptions ++= Seq(
   "-language:reflectiveCalls",
   "-Ywarn-numeric-widen",
   "-target:11",
+  "-Xlint:-byname-implicit",
   "-Xlint"
 )
 
 enablePlugins(SbtTwirl)
 
-val http4sVersion = "0.23.1"
+val http4sVersion = "0.23.6"
 
 assembly / assemblyMergeStrategy := {
   case PathList(xs @ _*) if xs.last == "io.netty.versions.properties" => MergeStrategy.rename
@@ -32,9 +33,9 @@ libraryDependencies ++= Seq(
   "org.http4s" %% "http4s-circe" % http4sVersion,
   // Optional for auto-derivation of JSON codecs
   "io.circe" %% "circe-generic" % "0.14.1",
-  "org.typelevel" %% "cats-effect" % "3.2.2",
-  "co.fs2" %% "fs2-core" % "3.1.0",
-  "co.fs2" %% "fs2-io" % "3.1.0",
+  "org.typelevel" %% "cats-effect" % "3.3.0",
+  "co.fs2" %% "fs2-core" % "3.2.2",
+  "co.fs2" %% "fs2-io" % "3.2.2",
   "io.getquill" %% "quill-jasync-postgres" % "3.9.0",
   "io.getquill" %% "quill-jasync" % "3.9.0",
   "ch.qos.logback" % "logback-classic" % "1.2.5"

+ 0 - 0
frameworks/Scala/http4s/project/build.properties → frameworks/Scala/http4s/blaze/project/build.properties


+ 0 - 0
frameworks/Scala/http4s/project/plugins.sbt → frameworks/Scala/http4s/blaze/project/plugins.sbt


+ 0 - 0
frameworks/Scala/http4s/src/main/resources/application.properties → frameworks/Scala/http4s/blaze/src/main/resources/application.properties


+ 0 - 0
frameworks/Scala/http4s/src/main/resources/logback.xml → frameworks/Scala/http4s/blaze/src/main/resources/logback.xml


+ 0 - 0
frameworks/Scala/http4s/src/main/scala/http4s/techempower/benchmark/DatabaseService.scala → frameworks/Scala/http4s/blaze/src/main/scala/http4s/techempower/benchmark/DatabaseService.scala


+ 2 - 6
frameworks/Scala/http4s/src/main/scala/http4s/techempower/benchmark/WebServer.scala → frameworks/Scala/http4s/blaze/src/main/scala/http4s/techempower/benchmark/WebServer.scala

@@ -1,7 +1,6 @@
 package http4s.techempower.benchmark
 
 import java.util.concurrent.Executors
-import scala.concurrent.ExecutionContext
 import cats.effect.{ExitCode, IO, IOApp, Resource}
 import com.typesafe.config.ConfigValueFactory
 import io.circe.generic.auto._
@@ -13,7 +12,6 @@ import org.http4s._
 import org.http4s.dsl._
 import org.http4s.circe._
 import org.http4s.implicits._
-import org.http4s.server.Router
 import org.http4s.blaze.server.BlazeServerBuilder
 import org.http4s.headers.Server
 import org.http4s.twirl._
@@ -97,13 +95,11 @@ object WebServer extends IOApp with Http4sDsl[IO] {
         } yield newWorlds.asJson)
     })
 
-  val blazeEc = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(32))
-
   // Given a fully constructed HttpService, start the server and wait for completion
   def startServer(service: HttpRoutes[IO]) =
-    BlazeServerBuilder[IO](blazeEc)
+    BlazeServerBuilder[IO]
       .bindHttp(8080, "0.0.0.0")
-      .withHttpApp(Router("/" -> service).orNotFound)
+      .withHttpApp(service.orNotFound)
       .withSocketKeepAlive(true)
       .resource
 

+ 0 - 0
frameworks/Scala/http4s/src/main/twirl/index.scala.html → frameworks/Scala/http4s/blaze/src/main/twirl/index.scala.html


+ 11 - 5
frameworks/Scala/http4s/http4s.dockerfile

@@ -1,8 +1,8 @@
-FROM openjdk:15 AS builder
+FROM openjdk:17 AS builder
 WORKDIR /http4s
-COPY project project
-COPY src src
-COPY build.sbt build.sbt
+COPY blaze/project project
+COPY blaze/src src
+COPY blaze/build.sbt build.sbt
 COPY sbt sbt
 RUN ./sbt assembly -batch && \
     mv target/scala-2.13/http4s-assembly-1.0.jar . && \
@@ -11,7 +11,8 @@ RUN ./sbt assembly -batch && \
     rm -Rf ~/.sbt && \
     rm -Rf ~/.ivy2 && \
     rm -Rf /var/cache
-FROM openjdk:15
+    
+FROM openjdk:17
 WORKDIR /http4s
 COPY --from=builder /http4s/http4s-assembly-1.0.jar /http4s/http4s-assembly-1.0.jar
 
@@ -21,6 +22,11 @@ CMD java \
       -server \
       -Xms2g \
       -Xmx2g \
+      -XX:NewSize=1g \
+      -XX:MaxNewSize=1g \
+      -XX:InitialCodeCacheSize=256m \
+      -XX:ReservedCodeCacheSize=256m \
+      -XX:+UseParallelGC \
       -XX:+AlwaysPreTouch \
       -Dcats.effect.stackTracingMode=disabled \
       -jar \