使用template软件包为客户端生成动态网页时,速度太慢。
测试代码如下,golang 1.4.1
http.Handle("/js/", (http.FileServer(http.Dir(webpath))))
http.Handle("/css/", (http.FileServer(http.Dir(webpath))))
http.Handle("/img/", (http.FileServer(http.Dir(webpath))))
http.HandleFunc("/test", TestHandler)
func TestHandler(w http.ResponseWriter, r *http.Request) {
Log.Info("Entering TestHandler ...")
r.ParseForm()
filename := NiConfig.webpath + "/test.html"
t, err := template.ParseFiles(filename)
if err != nil {
Log.Error("template.ParseFiles err = %v", err)
}
t.Execute(w, nil)
}
根据日志,我发现在中花了大约3秒钟t.Execute(w, nil),但我不知道为什么要花这么多时间。我还尝试了Apache服务器进行测试test.html,它的响应速度非常快。