Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Simple throughput benchmark in Go
# Ran this on my 2014 MBA 13" 1.7 GHz i7, 8GB Ram.
$ go version
go version go1.2.1 darwin/amd64
$ go build go-web.go
$ GOMAXPROCS=4 ./go-web &
$ wrk -t10 -c400 http://localhost:8080
Running 10s test @ http://localhost:8080
10 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 4.72ms 1.33ms 47.42ms 95.49%
Req/Sec 5.56k 3.57k 14.00k 56.97%
524490 requests in 10.00s, 64.02MB read
Socket errors: connect 159, read 77, write 0, timeout 636
Requests/sec: 52455.45
Transfer/sec: 6.40MB
package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello world")
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}

That's awesome! I got

This is on a 2014 MBP 13" 2.8 Ghz i7, 16Gb ram
go version
go version go1.2.2 darwin/amd64
kristian@tinkerbox  ~/code/go-example ‹2.1.1›
➜ go build go-web.go
kristian@tinkerbox  ~/code/go-example ‹2.1.1›
➜ GOMAXPROCS=4 ./go-web &
[1] 91118
kristian@tinkerbox  ~/code/go-example ‹2.1.1›
➜ wrk -t10 -c400 http://localhost:8080
Running 10s test @ http://localhost:8080
  10 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     7.14ms    2.62ms 350.05ms   91.59%
    Req/Sec     5.53k     1.28k   10.93k    70.04%
  530730 requests in 10.00s, 64.79MB read
  Socket errors: connect 0, read 240, write 0, timeout 0
Requests/sec:  53071.17
Transfer/sec:      6.48MB

I decided to write a similar example using dynamo:

defmodule HelloWorld do
  use Dynamo
  use Dynamo.Router

  config :server, port: 8888, acceptors: 10000, max_connections: 100000

  get "/" do
    conn.resp_body("Hello World!")
  end
end

Running the above

➜ iex -S mix
Erlang/OTP 17 [erts-6.0] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Compiled lib/hello_world.ex
Generated elixir_hello_world.app
Interactive Elixir (0.13.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> HelloWorld.start_link
{:ok, #PID<0.124.0>}
iex(2)> HelloWorld.run
Running HelloWorld at http://localhost:8888 with Cowboy on prod
:ok
iex(3)>

Gave this result

➜ wrk -t10 -c400 http://localhost:8888
Running 10s test @ http://localhost:8888
  10 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    14.84ms   16.72ms 249.04ms   92.14%
    Req/Sec     3.32k     1.49k   14.81k    76.23%
  312975 requests in 10.00s, 53.71MB read
  Socket errors: connect 0, read 149, write 0, timeout 0
Requests/sec:  31295.46
Transfer/sec:      5.37MB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment