To view parent comment, click here.
To read all comments associated with this story, please click here.
Nothing special, just:
GOMAXPROCS=4
hello.go ----------------------------------------------
package main
import (
"net/http"
"fmt"
"strconv"
)
var hellostr string="HelloWorld"
var hellolen string=strconv.Itoa(len(hellostr))
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=UTF-8")
w.Header().Set("Content-Length", hellolen) // this icreases server performance 2x ,from 11kRPS to 22k RPS (requests per second)
fmt.Fprintf(w, hellostr);
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
---------------------------------------------------
Your posted program would get 6-8k per run on my machine with ab -k -n 200000 -c 800 http://localhost:8080/
The below program gets 60,000+ RPS on my machine, changes:
* Set max procs dynamicaly
* Stopped net/http go from getting and sending the time with every request
* used fprint rather than fprintf (faster)
package main
import (
"fmt"
"net/http"
"strconv"
"runtime"
)
const hellostr = "HelloWorld"
var hellolen string = strconv.Itoa(len(hellostr))
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=UTF-8")
w.Header().Set("Content-Length", hellolen) // 2x faster ,from 11k RPS to 22k RPS (requests per second)
w.Header().Set("Date", "")
fmt.Fprint(w, hellostr)
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU()/2 + 1)
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}




Member since:
2005-09-03
"BTW do you know any other optimization tricks?"
I'd be happy to take a look, can you post a link to your latest code?
As far as documentation, check out http://golang.org/pkg/
Specifically regarding headers: http://golang.org/pkg/net/http/#Header