1
0
mirror of https://github.com/golang/go synced 2024-11-12 09:20:22 -07:00

net/http: more request benchmarks

Add benchmarks for common http benchmarking tools. The intent is to catch optimisations which favor synthetic benchmarks that do not show improvements for real clients like Chrome.

BenchmarkReadRequestChrome        200000             10133 ns/op          60.29 MB/s        3148 B/op         32 allocs/op
BenchmarkReadRequestCurl          500000              4314 ns/op          18.08 MB/s         905 B/op         15 allocs/op
BenchmarkReadRequestApachebench   500000              4363 ns/op          18.79 MB/s         956 B/op         16 allocs/op
BenchmarkReadRequestSiege         500000              6408 ns/op          24.19 MB/s        1397 B/op         22 allocs/op
BenchmarkReadRequestWrk          1000000              2838 ns/op          14.09 MB/s         757 B/op         11 allocs/op

R=golang-dev, bradfitz
CC=golang-dev, haimuiba
https://golang.org/cl/7300075
This commit is contained in:
Dave Cheney 2013-02-10 08:18:09 +11:00
parent 1b3083e68d
commit 6ce3e99af0

View File

@ -403,6 +403,8 @@ Content-Disposition: form-data; name="textb"
`
func benchmarkReadRequest(b *testing.B, request string) {
request = request + "\n" // final \n
request = strings.Replace(request, "\n", "\r\n", -1) // expand \n to \r\n
b.SetBytes(int64(len(request)))
r := bufio.NewReader(&infiniteReader{buf: []byte(request)})
b.ReportAllocs()
@ -428,16 +430,9 @@ func (r *infiniteReader) Read(b []byte) (int, error) {
return n, nil
}
func min(a, b int) int {
if a > b {
return b
}
return a
}
func BenchmarkReadRequest(b *testing.B) {
func BenchmarkReadRequestChrome(b *testing.B) {
// https://github.com/felixge/node-http-perf/blob/master/fixtures/get.http
const request = `GET / HTTP/1.1
benchmarkReadRequest(b, `GET / HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
@ -446,7 +441,41 @@ Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: __utma=1.1978842379.1323102373.1323102373.1323102373.1; EPi:NumberOfVisits=1,2012-02-28T13:42:18; CrmSession=5b707226b9563e1bc69084d07a107c98; plushContainerWidth=100%25; plushNoTopMenu=0; hudson_auto_refresh=false
`
benchmarkReadRequest(b, strings.Replace(request, "\n", "\r\n", -1))
`)
}
func BenchmarkReadRequestCurl(b *testing.B) {
// curl http://localhost:8080/
benchmarkReadRequest(b, `GET / HTTP/1.1
User-Agent: curl/7.27.0
Host: localhost:8080
Accept: */*
`)
}
func BenchmarkReadRequestApachebench(b *testing.B) {
// ab -n 1 -c 1 http://localhost:8080/
benchmarkReadRequest(b, `GET / HTTP/1.0
Host: localhost:8080
User-Agent: ApacheBench/2.3
Accept: */*
`)
}
func BenchmarkReadRequestSiege(b *testing.B) {
// siege -r 1 -c 1 http://localhost:8080/
benchmarkReadRequest(b, `GET / HTTP/1.1
Host: localhost:8080
Accept: */*
Accept-Encoding: gzip
User-Agent: JoeDog/1.00 [en] (X11; I; Siege 2.70)
Connection: keep-alive
`)
}
func BenchmarkReadRequestWrk(b *testing.B) {
// wrk -t 1 -r 1 -c 1 http://localhost:8080/
benchmarkReadRequest(b, `GET / HTTP/1.1
Host: localhost:8080
`)
}