Multithreaded Crystal initial thoughts

Removing the JSON serialization from the Go app only added ~18% throughput.

  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   109.05us  119.22us   9.19ms   99.46%
Requests/sec:  81592.82
Golang code here
package main

import (
  "fmt"
  "log"
  "net/http"
)

func main() {
  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello")
  })

  log.Fatal(http.ListenAndServe(":54321", nil))
}

It appears Crystal returns a nontrivial JSON payload faster than Go writes a hard-coded string, but let’s check Crystal anyway:

  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    54.06us   23.38us 723.00us   96.85%
Requests/sec: 173259.23

I may be going out on a limb here but … ummm … I think we’re good?

The only thing I changed in the Crystal code was to make the call method just run context.response << "Hello" to match the Go app (also removed the Fiber.yield for the same reason).

4 Likes