Skip to content

Instantly share code, notes, and snippets.

@ChristopherDavenport
Last active June 16, 2023 01:11
Show Gist options
  • Save ChristopherDavenport/2e5ad15cd293aa0816090f8677b8cc3b to your computer and use it in GitHub Desktop.
Save ChristopherDavenport/2e5ad15cd293aa0816090f8677b8cc3b to your computer and use it in GitHub Desktop.
Random Benchmarks around Ember and
import cats.syntax.all._
import cats.effect._
import fs2._
import fs2.io.net._
import com.comcast.ip4s._
object CheatApp extends IOApp {
val parallelism = Int.MaxValue
def run(args: List[String]): IO[ExitCode] = {
fs2.io.net.Network[IO].server(
host"0.0.0.0".some,
port"8080".some,
List.empty
).map(socket =>
Stream.eval(
socket.read(4096)
).unNoneTerminate.evalMap{x =>
socket.write(Cheating.raw)
}.repeat
).parJoin(parallelism)
.compile
.drain
}.as(ExitCode.Success)
}
object Cheating {
val raw = fs2.Chunk.array(
"HTTP/1.1 200 Ok\r\nContent-Length: 0\r\nDate: Thurs, 15 Jun 2023 07:28:00 GMT\r\n\r\n"
.getBytes()
)
}
import org.http4s.ember.server.EmberServerBuilder
object RealApp extends IOApp.Simple {
val const = org.http4s.Response[IO](org.http4s.Status.Ok)
val app = cats.data.Kleisli.pure[IO, org.http4s.Request[IO], org.http4s.Response[IO]](const)
def run = EmberServerBuilder.default[IO]
.withHttpApp(app)
.build.useForever
}

Cheat Before

wrk -t12 -c400 -d30s http://127.0.0.1:8080/
Running 30s test @ http://127.0.0.1:8080/
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     3.59ms    6.24ms 253.13ms   98.92%
    Req/Sec     6.07k     2.59k   12.07k    65.62%
  2170508 requests in 30.02s, 159.39MB read
  Socket errors: connect 155, read 937, write 0, timeout 0
Requests/sec:  72299.81
Transfer/sec:      5.31MB

Cheat After

wrk -t12 -c400 -d30s http://127.0.0.1:8080/
Running 30s test @ http://127.0.0.1:8080/
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     2.12ms    5.84ms 233.35ms   98.44%
    Req/Sec    11.08k     5.10k   22.85k    62.58%
  3960623 requests in 30.01s, 290.84MB read
  Socket errors: connect 155, read 1008, write 0, timeout 0
Requests/sec: 131975.07
Transfer/sec:      9.69MB

Blaze

wrk -t12 -c400 -d30s http://127.0.0.1:8080/
Running 30s test @ http://127.0.0.1:8080/
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     4.72ms    9.74ms 244.21ms   93.22%
    Req/Sec     6.31k     4.12k   26.16k    64.34%
  2245159 requests in 30.04s, 160.59MB read
  Socket errors: connect 155, read 375, write 0, timeout 0
Requests/sec:  74743.15
Transfer/sec:      5.35MB

Ember Before

wrk -t12 -c400 -d30s http://127.0.0.1:8080/
Running 30s test @ http://127.0.0.1:8080/
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     5.19ms   17.05ms 487.71ms   98.89%
    Req/Sec     5.05k     2.51k   11.17k    61.68%
  1797692 requests in 30.03s, 169.73MB read
  Socket errors: connect 155, read 853, write 1, timeout 0
Requests/sec:  59854.80
Transfer/sec:      5.65MB

Ember After

wrk -t12 -c400 -d30s http://127.0.0.1:8080/
Running 30s test @ http://127.0.0.1:8080/
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     8.98ms   55.97ms   1.30s    98.65%
    Req/Sec     7.06k     3.41k   14.89k    66.11%
  2513915 requests in 30.01s, 237.35MB read
  Socket errors: connect 155, read 1102, write 4, timeout 0
Requests/sec:  83782.46
Transfer/sec:      7.91MB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment