go - HTTP 客户端返回结果为 null
问题描述
我们在负载均衡器和其他东西下在生产中运行核心 go 服务器。
现在,当 goroutine 计数(带有 pprof 跟踪)超过 2500 时,我们的 HTTP 客户端将返回 nil 作为结果。
这是我的 HTTP 客户端代码。
client := &http.Client{
Timeout: time.Second * 130,
Transport: netTransport,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
go func() {
select {
case <-ctx.Done():
log.Error(ctx.Err()) // prints "context deadline exceeded"
return
}
}()
vars := mux.Vars(r)
validateTokenURL = authURL + "/" + vars["resource"] + "/authorized" + "?url=" + path
req, _ := http.NewRequest("GET", validateTokenURL, nil)
req.Header = r.Header
req = req.WithContext(ctx)
res, error := client.Do(req)
if error != nil {
log.Error("The group's number increased tremendously!")
return nil, nil, false
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Error(err.Error())
}
json.Unmarshal(body, &responseBody)
res.Body.Close()
if _, ok := responseBody["data"]; ok && strings.Compare(reflect.TypeOf(responseBody["data"]).String(), "string") == 0 && strings.Compare(responseBody["data"].(string), "ok") == 0 {
return responseBody, res, true
}
return responseBody, res, false
}
我已将 ulimit 设置为大约 8 GB,另外还有 16 GB 作为 RAM。内存使用率低于 20%。
谁能帮助我们弄清楚我们缺少什么?
解决方案
推荐阅读
- c# - EPPlus SUMIFS 返回值 #VALUE
- python - 在 tkinter 中管理用户输入小部件
- html - 发送文件返回空白视频
- c++ - QtConcurrent::mapped 返回类型问题
- css - 字体真棒图标未显示 css 内容属性
- c# - 在不使用循环的情况下计算 List 中的时间
- c++ - LAB_3.exe 中 0x00898809 处的未处理异常:0xC0000005:访问冲突读取位置 0xCCCCCCF4。发生了
- ruby - 如何使 Ruby YAML.load 以我想要的方式解析时间?
- postgresql - 配置 postgres 复制时服务器的启动备份映像
- mql4 - 如何使用 OrderModify() 修改所有当前未平仓头寸的止盈?