lundi 15 mars 2021

How to handle maximum number of connections issue for http client?

We have a http GET handler that inturn uses http client to connect to another server.

type ProductHandler struct {
    service1       Service1
    service2       Service2
}


type Service2 struct {
    field1             int
    field2             string
    client             CustomHttpClient
}

CustomHttpClient uses http.Client type from https://golang.org/src/net/http/client.go


As http.Client is concurrent safe, we are using single http client for multiple GET requests, by registering ProductHandler{} for GET requests.

But the problem is, http.Client limits the number of GET requests served by ProductHandler, due to number of file descriptors in Linux(default 1024), which are limited. To be specific, MaxConnsPerHost in http.Transport limited by Linux file descriptors.

How to address the problem of GET requests limited by number of file descriptors in CustomHttpClient? raising ulimit is just a work around...

Aucun commentaire:

Enregistrer un commentaire