Skip to content

Instantly share code, notes, and snippets.

@physacco
Last active December 14, 2015 16:18
Show Gist options
  • Save physacco/5113741 to your computer and use it in GitHub Desktop.
Save physacco/5113741 to your computer and use it in GitHub Desktop.
A simple HTTP server in Go. From A Tour of Go.
package main
import (
"fmt"
"runtime"
"net/http"
)
type Hello struct{}
func (h Hello) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "It works!")
}
func main() {
runtime.GOMAXPROCS(4); // 4 cores
h := Hello{}
http.ListenAndServe("localhost:8000", h)
}

http-hello benchmark

compile and run

# ulimit -n 20480
# go run http-hello.go

benchmark with ab

ab -n 10000 -c 100 http://127.0.0.1:8000/

ab output

Server Hostname:        127.0.0.1
Server Port:            8000

Document Path:          /
Document Length:        9 bytes

Concurrency Level:      100
Time taken for tests:   1.767 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      1254750 bytes
HTML transferred:       90342 bytes
Requests per second:    5659.95 [#/sec] (mean)
Time per request:       17.668 [ms] (mean)
Time per request:       0.177 [ms] (mean, across all concurrent requests)
Transfer rate:          693.54 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        2    7   2.1      7      17
Processing:     4   10   2.2     10      20
Waiting:        1    7   2.1      7      17
Total:          7   18   2.6     17      30

Percentage of the requests served within a certain time (ms)
  50%     17
  66%     18
  75%     19
  80%     20
  90%     21
  95%     22
  98%     23
  99%     24
 100%     30 (longest request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment