---------- Forwarded message ----------
From:
John Barham <jba...@gmail.com>
Date: 2012/3/6
Subject: Re: [go-nuts] Golang http server is ridiculously slow
To:
denis.ch...@gmail.comCc: Brad Fitzpatrick <
brad...@golang.org>,
golan...@googlegroups.com
On Tue, Mar 6, 2012 at 10:17 AM, Brad Fitzpatrick <
brad...@golang.org> wrote:
> You should try setting the Content-Length & Content-Type in the Go version,
> like you are in the Python version. Then you avoid chunking and sniffing,
> respectively. Also, have both send the same output. Also, verify they're
> both sending the same headers. Go sends some HTTP headers that are
> "SHOULDs" but you can turn off if you really care about bandwidth.
>
> Also, use a recent weekly release. The last "release" version of Go was a
> long time ago and much has been improved.
>
>
> On Mon, Mar 5, 2012 at 2:19 PM, <
denis.ch...@gmail.com> wrote:
>>
>> Hello!
>> I wonder why the go http server is SO slow? In fact, it's more than twice
>> slower than python version that uses gevent.
>> I tried both weekly and release compilers, but nothing changed, they both
>> are slow.
>> In perflog.log result of gevent at the top then golang server one at the
>> bottom. The python version is twice faster.
Set the headers and turn on GOMAXPROCS and Go is faster:
$ cat a.py
#!/usr/bin/python2.7
from gevent import http
def callback(request):
body = '<b>hello world</b>'
request.add_output_header('Content-Type', 'text/html')
request.add_output_header('Content-Length', str(len(body)))
request.send_reply(200, "OK", body)
print 'Serving on 8088...'
http.HTTPServer(('0.0.0.0', 8088), callback).serve_forever()
$ python2.7 a.py &
$ ab -q -c 50 -n 100000
http://127.0.0.1:8088/ | grep "Requests per second"
Requests per second: 14557.18 [#/sec] (mean)
$ go version
go version weekly.2012-03-04 +f4470a54e6db
$ cat a.go
package main
import (
"io"
"net/http"
"strconv"
)
func HelloServer(c http.ResponseWriter, req *http.Request) {
body := "<b>hello world</b>"
c.Header().Add("Content-Type", "text/html")
c.Header().Add("Content-Length", strconv.Itoa(len(body)))
io.WriteString(c, body)
}
func main() {
http.Handle("/", http.HandlerFunc(HelloServer))
http.ListenAndServe(":8080", nil)
}
$ GOMAXPROCS=4 go run a.go &
$ ab -q -c 50 -n 100000
http://127.0.0.1:8080/ | grep "Requests per second"
Requests per second: 20152.81 [#/sec] (mean)
That's running on a 2.67 GHz i5 in 386 mode. The amd64 Go version
would likely be even faster.
FWIW the gevent library is a 3rd party extension to Python whereas the
Go version is all standard library.
John