@@ -33,17 +33,25 @@ type Client interface {
3333 Get (ctx context.Context , target * url.URL , ep datalayer.Addressable ) (PrometheusMetricMap , error )
3434}
3535
36- // -- package implementations --
3736const (
37+ // the maximum idle connection count is shared by all endpoints. The value is
38+ // set high to ensure the number of idle connection is above the expected
39+ // endpoint count. Setting it too low would cause thrashing of the idle connection
40+ // pool and incur higher overheads for every GET (e.g., socket initiation, certificate
41+ // exchange, connections in timed wait state, etc.).
3842 maxIdleConnections = 5000
39- maxIdleTime = 10 * time .Second
40- timeout = 10 * time .Second
43+ maxIdleTime = 10 * time .Second // once a endpoint goes down, allow closing.
44+ timeout = 10 * time .Second // mostly guard against unresponsive endpoints.
45+ // allow some grace when connections are not made idle immediately (e.g., parsing
46+ // and updating might take some time). This allows maintaining up to two idle connections
47+ // per endpoint (defined as scheme://host:port).
48+ maxIdleConnsPerHost = 2
4149)
4250
4351var (
4452 baseTransport = & http.Transport {
4553 MaxIdleConns : maxIdleConnections ,
46- MaxIdleConnsPerHost : 4 , // host is defined as scheme://host:port
54+ MaxIdleConnsPerHost : maxIdleConnsPerHost ,
4755 // TODO: set additional timeouts, transport options, etc.
4856 }
4957 defaultClient = & client {
0 commit comments