首页 > 解决方案 > 如何处理 http 客户端的最大连接数问题?

问题描述

我们有一个 http GET 处理程序(ProductHandler),它反过来使用 http 客户端连接到另一个服务器。

type ProductHandler struct {
    service1       Service1
    service2       Service2
}


type Service2 struct {
    field1             int
    field2             string
    client             CustomHttpClient
}

CustomHttpClient使用http.Client来自的类型https://golang.org/src/net/http/client.go


由于http.Client并发安全,我们通过注册 GET 请求来使用单个 http 客户端来处理多个 GETProductHandler{}请求。

GET 请求由http.Serverfrom提供服务https://golang.org/src/net/http/server.go

但问题是,由于 Linux 中的文件描述符数量(默认 1024)是有限的,因此http.Client限制了 GET 请求的数量。ProductHandler具体来说,受Linux文件描述符MaxConnsPerHost的限制。http.Transport


如何解决 GET 请求受文件描述符数量限制的问题CustomHttpClient?提高ulimit只是一个工作...

标签: linuxmultithreadinggoforkgoroutine

解决方案


推荐阅读