Skip to content

Commit

Permalink
Merge pull request #809 from finagle/vk/wrk-bench
Browse files Browse the repository at this point in the history
Update wrk benchmark and numbers
  • Loading branch information
vkostyukov authored Jun 19, 2017
2 parents c07125f + b4a4cba commit 27f1b6b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 48 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ Performance
We use [wrk][wrk] to load test [Finch+Circe][finch-bench] against [Finagle+Jackson][finagle-bench]
to get some insight on how much overhead, an idiomatic Finch application written in a purely
functional way, involves on top of Finagle/Jackson. The results are quite impressive (for a pre-1.0
version): Finch performs on **85% of Finagle's throughput**.
version): Finch performs on **95% of Finagle's throughput**.

Here is the first three runs of the benchmark on 2013 MB Pro (2.8 GHz Intel Core i7 w/ 16G RAM).

| Benchmark | Run 1 | Run 2 | Run 3 |
|-------------------|----------------|----------------|----------------|
| Finagle + Jackson | 33867.56 req/s | 43781.26 req/s | 43854.92 req/s |
| Finch + Circe | 27126.25 req/s | 36720.75 req/s | 37191.58 req/s |
| Finagle + Jackson | 29014.68 req/s | 36783.21 req/s | 39924.42 req/s |
| Finch + Circe | 28762.84 req/s | 36876.30 req/s | 37447.52 req/s |

Finch is also load tested against a number of Scala HTTP frameworks and libraries as part of the
[TechEmpower benchmark][tempower]. The most recent round showed that Finch performs really well
Expand Down
32 changes: 14 additions & 18 deletions examples/src/main/scala/io/finch/wrk/Finagle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.finch.wrk
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.twitter.finagle.Service
import com.twitter.finagle.http.{Method, Request, Response, Status}
import com.twitter.finagle.http.{Request, Response, Status}
import com.twitter.io.Buf
import com.twitter.util.Future
import io.finch.internal._
Expand All @@ -12,33 +12,29 @@ import io.finch.internal._
* How to benchmark this:
*
* 1. Run the server: sbt 'examples/runMain io.finch.wrk.Finagle'
* 2. Run wrk: wrk -t4 -c24 -d30s -s examples/src/main/scala/io/finch/wrk/wrk.lua http://localhost:8081/
* 2. Run wrk: wrk -t4 -c24 -d30s http://localhost:8081/
*
* Rule of thumb for picking values for params `t` and `c` (given that `n` is a number of logical
* cores your machine has, including HT):
*
* t = n
* c = t * n * 1.5
*/
object Finagle extends App {
object Finagle extends Wrk {

val mapper: ObjectMapper = new ObjectMapper().registerModule(DefaultScalaModule)

val roundTrip: Service[Request, Response] = new Service[Request, Response] {
def apply(req: Request): Future[Response] =
if (req.method != Method.Post) Future.value(Response(req.version, Status.NotFound))
else {
val payloadIn = mapper.readValue(req.contentString, classOf[Payload])
val payloadOut = mapper.writeValueAsBytes(payloadIn)
serve(new Service[Request, Response] {
def apply(req: Request): Future[Response] = {
val payload = mapper.writeValueAsBytes(Payload("Hello, World!"))

val rep = Response(req.version, Status.Ok)
rep.content = Buf.ByteArray.Owned(payloadOut)
rep.contentType = "application/json"
rep.date = currentTime()
val rep = Response(req.version, Status.Ok)
rep.content = Buf.ByteArray.Owned(payload)
rep.contentType = "application/json"
rep.date = currentTime()
rep.server = "Finagle"

Future.value(rep)
}
}

serve(roundTrip)
Future.value(rep)
}
})
}
6 changes: 3 additions & 3 deletions examples/src/main/scala/io/finch/wrk/Finch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import io.finch.circe._
* How to benchmark this:
*
* 1. Run the server: sbt 'examples/runMain io.finch.wrk.Finch'
* 2. Run wrk: wrk -t4 -c24 -d30s -s examples/src/main/scala/io/finch/wrk/wrk.lua http://localhost:8081/
* 2. Run wrk: wrk -t4 -c24 -d30s http://localhost:8081/
*
* Rule of thumb for picking values for params `t` and `c` (given that `n` is a number of logical
* cores your machine has, including HT):
*
* t = n
* c = t * n * 1.5
*/
object Finch extends App {
serve(post(jsonBody[Payload]).toServiceAs[Application.Json])
object Finch extends Wrk {
serve(Endpoint.lift(Payload("Hello, World!")).toServiceAs[Application.Json])
}
4 changes: 0 additions & 4 deletions examples/src/main/scala/io/finch/wrk/Payload.scala

This file was deleted.

20 changes: 20 additions & 0 deletions examples/src/main/scala/io/finch/wrk/Wrk.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.finch.wrk

import com.twitter.finagle.{Http, Service}
import com.twitter.finagle.http.{Request, Response}
import com.twitter.finagle.stats.NullStatsReceiver
import com.twitter.finagle.tracing.NullTracer
import com.twitter.util.Await

abstract class Wrk extends App {

case class Payload(message: String)

protected def serve(s: Service[Request, Response]): Unit = Await.ready(
Http.server
.withCompressionLevel(0)
.withStatsReceiver(NullStatsReceiver)
.withTracer(NullTracer)
.serve(":8081", s)
)
}
17 changes: 0 additions & 17 deletions examples/src/main/scala/io/finch/wrk/package.scala

This file was deleted.

3 changes: 0 additions & 3 deletions examples/src/main/scala/io/finch/wrk/wrk.lua

This file was deleted.

0 comments on commit 27f1b6b

Please sign in to comment.