
从
pprof您在注释中提供的堆中,看来您正在通过
gorilla/sessions和
gorilla/context(将近400MB)泄漏内存。
- 请参阅以下ML线程:[https](https://groups.google.com/forum/#!msg/gorilla-
- web/clJfCzenuWY/N_Xj9-5Lk6wJ) :
- [//groups.google.com/forum/#!](https://groups.google.com/forum/#!msg/gorilla-
- web/clJfCzenuWY/N_Xj9-5Lk6wJ) msg/gorilla-web/clJfCzenuWY/
- [N_Xj9-5Lk6wJ](https://groups.google.com/forum/#!msg/gorilla-
- web/clJfCzenuWY/N_Xj9-5Lk6wJ)和此GH问题:https
- //github.com/gorilla/sessions/issues/
15
这是一个泄漏速度非常快的版本:
package mainimport ( "fmt" // "github.com/gorilla/context" "github.com/gorilla/sessions" "net/http")var ( cookieStore = sessions.NewcookieStore([]byte("cookie-secret")))func main() { http.HandleFunc("/", defaultHandler) http.ListenAndServe(":8080", nil)}func defaultHandler(w http.ResponseWriter, r *http.Request) { cookieStore.Get(r, "leak-test") fmt.Fprint(w, "Hi there")}这是一个清理并具有相对静态的RSS的示例:
package mainimport ( "fmt" "github.com/gorilla/context" "github.com/gorilla/sessions" "net/http")var ( cookieStore = sessions.NewcookieStore([]byte("cookie-secret")))func main() { http.HandleFunc("/", defaultHandler) http.ListenAndServe(":8080", context.ClearHandler(http.DefaultServeMux))}func defaultHandler(w http.ResponseWriter, r *http.Request) { cookieStore.Get(r, "leak-test") fmt.Fprint(w, "Hi there")}欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)