Skip to content

Instantly share code, notes, and snippets.

@errnoh
Last active December 15, 2015 20:48
Show Gist options
  • Save errnoh/5320784 to your computer and use it in GitHub Desktop.
Save errnoh/5320784 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"net/http"
"runtime"
"strconv"
)
type MessageStruct struct {
Message string
}
func hello(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/javascript")
j, _ := json.Marshal(&MessageStruct{"Hello, world"})
w.Header().Set("Content-Length", strconv.Itoa(len(j)))
w.Write(j)
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
http.HandleFunc("/json", hello)
http.ListenAndServe(":8080", nil)
}
tested with https://github.com/wg/wrk
parameters: wrk -t8 -c400 -r10m http://localhost:8080/json
(UPDATE: running wrk on _different_ machine than the http server)
Go 1.0.3:
Making 10000000 requests to http://HTTPTARGET:8080/json
8 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 7.87ms 3.42ms 202.81ms 90.42%
Req/Sec 5.99k 223.13 8.00k 97.96%
10000010 requests in 3.30m, 1.30GB read
Socket errors: connect 0, read 0, write 0, timeout 17
Requests/sec: 50458.87
Transfer/sec: 6.74MB
Go 1.1 (go version devel +3346bb37412c Fri Apr 05 13:43:18 2013 +1100 linux/amd64):
Making 10000000 requests to http://HTTPTARGET:8080/json
8 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.61ms 1.02ms 10.60ms 81.10%
Req/Sec 19.04k 443.99 21.00k 90.82%
10000074 requests in 1.05m, 1.30GB read
Socket errors: connect 0, read 0, write 0, timeout 143
Requests/sec: 158248.92
Transfer/sec: 21.13MB
Netty (from https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/netty ):
Making 10000000 requests to http://HTTPTARGET:8080/
8 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.29ms 697.34us 15.05ms 87.34%
Req/Sec 21.91k 599.71 28.00k 82.05%
10000048 requests in 0.93m, 1.68GB read
Socket errors: connect 0, read 0, write 0, timeout 93
Requests/sec: 178662.24
Transfer/sec: 30.67MB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment