性能分析
package main
import (
"fmt"
"net/http"
_ "net/http/pprof"
"time"
)
func slow(w http.ResponseWriter, req *http.Request) {
time.Sleep(time.Second * 5)
w.Write([]byte("a slow return"))
}
func fast(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("a fast return"))
}
func endless(w http.ResponseWriter, req *http.Request) {
for {
time.Sleep(time.Second)
if false {
break
}
}
w.Write([]byte("you will never see this message"))
}
func main() {
http.HandleFunc("/slow", slow)
http.HandleFunc("/fast", fast)
http.HandleFunc("/endless", endless)
if err := http.ListenAndServe("localhost:8080", nil); err != nil {
fmt.Println(err)
}
}


最后更新于
