-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTPClient大量请求没有释放 #1822
Comments
g.Client() 底层是对原生http.Client的封装, 代码见 Lines 59 to 71 in 583d576
http.Client原生是支持连接池的处理的, http.Transport的MaxConnsPerHost和MaxIdleConnsPerHost属性控制了每个Client最大支持的请求对象的数量, MaxIdleConns属性控制了保持多少个活跃连接. 所以其实在for循环里一直创建gClient对象不是一个好的处理方案. 但是我看了gClient的方法,并没有自定义http.Client的方式, 是否考虑加一个相关的方法?可以开一个help wanted 我来操作一波 @gqcn 。 @xxxlzj520 如果你比较着急的话, 我建议你使用gpool的方式来做实现. 文档见 https://goframe.org/pages/viewpage.action?pageId=1114377 |
@huangqian1985 @xxxlzj520 是的,本来 加了 package main
import (
"fmt"
"net/http"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
c := g.Client()
defer c.CloseIdleConnections()
c.Transport.(*http.Transport).MaxConnsPerHost = 3
for {
r, err := c.Get(gctx.New(), `https://baidu.com`)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(r.StatusCode)
_ = r.Close()
}
}
} |
[WeOpen Star]I would like to help |
gf版本:v2.0.6
现像描述:当for循环调用请求时,数据过多会导致请求没有释放,本地打开文件数过多
The text was updated successfully, but these errors were encountered: