栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Go http标准库中的内存泄漏?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Go http标准库中的内存泄漏?

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")}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/426878.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号