From e58305a5ad01f379a6d4c0d18b6e79a019bac0de Mon Sep 17 00:00:00 2001 From: Scott T Weaver Date: Tue, 20 Sep 2022 15:57:39 -0500 Subject: [PATCH] Fix zio-http 'Main'. I was still referencing "old school" zhttp. * Also changed some bits from 'techempower' to 'zio'. --- .../Scala/zio-http/src/main/scala/Main.scala | 48 ++++++++++--------- tfb | 4 +- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/frameworks/Scala/zio-http/src/main/scala/Main.scala b/frameworks/Scala/zio-http/src/main/scala/Main.scala index 9a82c0309ae..0ab0e6d50cb 100644 --- a/frameworks/Scala/zio-http/src/main/scala/Main.scala +++ b/frameworks/Scala/zio-http/src/main/scala/Main.scala @@ -1,19 +1,15 @@ -import zhttp.service.{EventLoopGroup, Server} +package zio.http + import zio._ -import zhttp.http._ -import zhttp.service.server.ServerChannelFactory +import zio.http._ import com.github.plokhotnyuk.jsoniter_scala.core._ import com.github.plokhotnyuk.jsoniter_scala.macros._ - import io.netty.util.AsciiString -import java.time.format.DateTimeFormatter -import java.time.{Instant, ZoneOffset} - case class Message(message: String) -object Main extends App { - private val message: String = "Hello, World!" +object Main extends ZIOAppDefault { + private val message: String = "Hello, World!" implicit val codec: JsonValueCodec[Message] = JsonCodecMaker.make private val plaintextPath = "/plaintext" @@ -33,6 +29,8 @@ object Main extends App { .withServer(STATIC_SERVER_NAME) .freeze + implicit val unsafe: Unsafe = Unsafe.unsafe + private def plainTextApp(response: Response) = Http.fromHExit(HExit.succeed(response)).whenPathEq(plaintextPath) private def jsonApp(json: Response) = Http.fromHExit(HExit.succeed(json)).whenPathEq(jsonPath) @@ -42,17 +40,21 @@ object Main extends App { jsonResponse <- JsonResponse } yield plainTextApp(plainTextResponse) ++ jsonApp(jsonResponse) - override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = - app - .flatMap(server(_).make.useForever) - .provideCustomLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(8)) - .exitCode - - private def server(app: HttpApp[Any, Nothing]) = - Server.app(app) ++ - Server.port(8080) ++ - Server.withError(_ => UIO.unit) ++ - Server.disableLeakDetection ++ - Server.consolidateFlush ++ - Server.disableFlowControl -} + + val config = ZLayer.succeed( + ServerConfig.default + .copy( + nThreads = 8, + consolidateFlush = true, + flowControl = false, + leakDetectionLevel = ServerConfig.LeakDetectionLevel.DISABLED, + ), + ) + + override val run = + app + .tap(_ => ZIO.debug(s">>>>>>>>>>>>>>>>>>>>>> STARTING BENCHMARK SERVER <<<<<<<<<<<<<<<<<<<<<<<<<<")) + .flatMap(Server.serve(_, None)) + .provide(config, Server.live) + +} \ No newline at end of file diff --git a/tfb b/tfb index 434a5a00595..e7509c4d70c 100755 --- a/tfb +++ b/tfb @@ -102,5 +102,5 @@ if ! docker network inspect tfb >/dev/null 2>&1; then fi test -t 1 && USE_TTY="-t" -docker build -t techempower/tfb - < ${SCRIPT_ROOT}/Dockerfile -exec docker run -i ${USE_TTY} --rm --network tfb -v /var/run/docker.sock:/var/run/docker.sock -v ${SCRIPT_ROOT}:/FrameworkBenchmarks techempower/tfb "${@}" +docker build -t zio/tfb - < ${SCRIPT_ROOT}/Dockerfile +exec docker run -i ${USE_TTY} --rm --network tfb -v /var/run/docker.sock:/var/run/docker.sock -v ${SCRIPT_ROOT}:/FrameworkBenchmarks -p 8080:8080 zio/tfb "${@}"