7

templateパッケージを使用して動的 Web ページをクライアントに生成すると、非常に遅くなります。

以下のコードのテスト、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してみましたが、非常に高速に応答しました。

4

1 に答える 1