package main
import (
"fmt"
"net/http"
"runtime"
)
func serve(w http.ResponseWriter, r *http.Request) {
r.Body.Close()
w.Write([]byte("Hello, world.\n"))
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
http.HandleFunc("/", serve)
http.ListenAndServe(":5000", nil)
}
I'm testing 'helloworld' Node.js, Python-Flask, and Go web servers using 'ab' (also siege). Seems that Go is running out of sockets (regardless of ab or siege), while Node & Python are just fine.[This question (with code) is also posted on stackexchange.]Any suggestions about how I can get an apples for apples comparison here without modifying fd count or system variables?How do I force the socket to close after serving the page?I understand that I can increase the open socket threshold for the test. However, Node and Python are running just fine, so, as I see it, either the Go code needs to be modified to make it comparable or there is a problem with the http package.
Tamás made good improvements. I would suggest using ab -r too.
That is excellent news. I cannot suggest which fix resolved your problem as I do not think I properly understood the issue. You can review the change log of the http package with
hg log $GOROOT/src/pkg/net/http | less
Go 1.0.3 was published in august (I think)
--