【发布时间】:2019-10-22 11:33:30
【问题描述】:
我有一个用 Go 编写的相对较大的 Web 应用程序,它使用 Gorilla's mux 进行路由。我最近意识到我的 Web 应用程序很慢,我想对 Web 应用程序进行分析。
阅读后,似乎net/http/pprof 是我需要的。但我不能让它与 mux 一起运行;即使是最简单的 Web 应用程序。
有人知道怎么做吗?
这是一个不起作用的琐碎代码示例(即/debug 没有提供任何服务)。
package main
import (
"fmt"
"github.com/gorilla/mux"
"math"
"net/http"
)
import _ "net/http/pprof"
func SayHello(w http.ResponseWriter, r *http.Request) {
for i := 0; i < 1000000; i++ {
math.Pow(36, 89)
}
fmt.Fprint(w, "Hello!")
}
func main() {
r := mux.NewRouter()
r.HandleFunc("/hello", SayHello)
http.ListenAndServe(":6060", r)
}
【问题讨论】:
标签: go