Created
August 12, 2020 14:43
-
-
Save tomwadeson/b8a211ce5c11b0754fa8a0d8fa793227 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example | |
import cats.effect.{ExitCode, IO, IOApp} | |
import org.http4s.HttpRoutes | |
import org.http4s.dsl.Http4sDsl | |
import org.http4s.server.blaze.BlazeServerBuilder | |
import org.http4s.implicits._ | |
import scala.concurrent.ExecutionContext | |
object Http4sCatsEffectServer extends IOApp { | |
override def run(args: List[String]): IO[ExitCode] = { | |
val httpApp = { | |
object dsl extends Http4sDsl[IO] | |
import dsl._ | |
HttpRoutes.of[IO] { | |
case GET -> Root => Ok("Hello, World!") | |
} | |
}.orNotFound | |
val server = | |
BlazeServerBuilder[IO](ExecutionContext.global) | |
.bindHttp(8080, "0.0.0.0") | |
.withHttpApp(httpApp) | |
.resource | |
server.use(_ => IO.never).as(ExitCode.Success) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example | |
import org.http4s.HttpRoutes | |
import org.http4s.dsl.Http4sDsl | |
import org.http4s.implicits._ | |
import org.http4s.server.blaze.BlazeServerBuilder | |
import zio.internal.Platform | |
import zio.interop.catz._ | |
import zio.interop.catz.implicits._ | |
import zio.{ExitCode, Task, URIO} | |
import scala.concurrent.ExecutionContext | |
object Http4sZioServer extends CatsApp { | |
override val platform: Platform = | |
Platform.benchmark | |
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = { | |
val httpApp = { | |
object dsl extends Http4sDsl[Task] | |
import dsl._ | |
HttpRoutes.of[Task] { | |
case GET -> Root => Ok("Hello, World!") | |
} | |
}.orNotFound | |
val server = | |
BlazeServerBuilder[Task](ExecutionContext.global) | |
.bindHttp(8081, "0.0.0.0") | |
.withHttpApp(httpApp) | |
.resource | |
server.toManaged.useForever | |
.catchAll(err => zio.console.putStrLn(s"Error: $err").as(ExitCode.failure)) | |
.as(ExitCode.success) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For `Http4sCatsEffectServer`, after warming up with two earlier runs: | |
$ wrk -c16 -t2 -d1m http://localhost:8080/ | |
Running 1m test @ http://localhost:8080/ | |
2 threads and 16 connections | |
Thread Stats Avg Stdev Max +/- Stdev | |
Latency 390.85us 1.56ms 69.00ms 99.32% | |
Req/Sec 23.87k 2.46k 31.47k 80.33% | |
2850186 requests in 1.00m, 353.36MB read | |
Requests/sec: 47456.01 | |
Transfer/sec: 5.88MB | |
For `Http4sZioServer`, after warming up with two earlier runs: | |
$ wrk -c16 -t2 -d1m http://localhost:8081/ | |
Running 1m test @ http://localhost:8081/ | |
2 threads and 16 connections | |
Thread Stats Avg Stdev Max +/- Stdev | |
Latency 1.76ms 574.61us 12.74ms 78.34% | |
Req/Sec 4.58k 424.11 5.28k 63.83% | |
546776 requests in 1.00m, 67.79MB read | |
Requests/sec: 9112.45 | |
Transfer/sec: 1.13MB | |
Hardware: | |
MBP (2018): i9 @ 2.9 GHz * 6 cores; 32 GB RAM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment