It is not possible for clients of http.Transport to dynamically change MaxIdleConnsPerHost attribute. It would be great to have a sync.RWMutex as an attribute of http.Transport, so this is possible.
The use case is that for HTTP/1.1 Hosts, it would be nice for the client to have the possibility of adjusting max-idle connections base on usage.
Making the following changes to http.Transport would add this feature:
// MaxIdleConnsPerHost, if non-zero, controls the maximum idle
// (keep-alive) connections to keep per-host. If zero,
// DefaultMaxIdleConnsPerHost is used.
MaxIdleConnsPerHost int
// MaxIdleConnsMutex, let you dynamically change the
// MaxIdleConnsPerHost without creating a data race.
//
// Usage:
//
// MaxIdleConnsMutex.Lock()
// MaxIdleConnsPerHost = newValue
// MaxIdleConnsMutex.Unlock()
//
MaxIdleConnsMutex sync.RWMutex
func (t *Transport) tryPutIdleConn(pconn *persistConn) error {
t.MaxIdleConnsMutex.RLock()
max := t.MaxIdleConnsPerHost
t.MaxIdleConnsMutex.RUnlock()
if t.DisableKeepAlives || max < 0 {
return errKeepAlivesDisabled
}
if pconn.isBroken() {
return errConnBroken
}
key := pconn.cacheKey
if max == 0 {
max = DefaultMaxIdleConnsPerHost
}
...
The text was updated successfully, but these errors were encountered:
Exposing a RWMutex is weird. There's no precedent for that. If anything it would be a setter method, and/or a pluggable conn pool mechanism for others to do whatever they want.
bradfitz
changed the title
It is not possible for clients of http.Transport to dynamically change MaxIdleConnsPerHost
net/http: mechanism to dynamically change MaxIdleConnsPerHost?
Mar 28, 2016
Please answer these questions before submitting your issue. Thanks!
go version
)?go env
)?It is not possible for clients of
http.Transport
to dynamically change MaxIdleConnsPerHost attribute. It would be great to have async.RWMutex
as an attribute ofhttp.Transport
, so this is possible.The use case is that for HTTP/1.1 Hosts, it would be nice for the client to have the possibility of adjusting max-idle connections base on usage.
The following gist shows the problem:
https://gist.github.com/go-loco/810fe53d8aee8879b8d1
Making the following changes to http.Transport would add this feature:
The text was updated successfully, but these errors were encountered: