diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-05-02 22:22:25 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-05-03 00:25:33 +0000 |
| commit | f459660cb85abd504845f93fdb65b1932bd6ac37 (patch) | |
| tree | 7f0934b2fcc1b19e78600e058e6521cb3e50c1dd /src | |
| parent | 6b019e216b4521c2375572a4edf2e08c1d9bc754 (diff) | |
| download | go-f459660cb85abd504845f93fdb65b1932bd6ac37.tar.xz | |
net/http: keep idle conns sorted by usage
Addressing feedback from Alan Su in https://golang.org/cl/22655
Change-Id: Ie0724efea2b4da67503c074e265ec7f8d7de7791
Reviewed-on: https://go-review.googlesource.com/22709
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/net/http/transport.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/net/http/transport.go b/src/net/http/transport.go index 032d8af4a1..7fdd94e05b 100644 --- a/src/net/http/transport.go +++ b/src/net/http/transport.go @@ -68,8 +68,8 @@ const DefaultMaxIdleConnsPerHost = 2 // See the package docs for more about HTTP/2. type Transport struct { idleMu sync.Mutex - wantIdle bool // user has requested to close all idle conns - idleConn map[connectMethodKey][]*persistConn + wantIdle bool // user has requested to close all idle conns + idleConn map[connectMethodKey][]*persistConn // most recently used at end idleConnCh map[connectMethodKey]chan *persistConn idleLRU connLRU @@ -690,7 +690,7 @@ func (t *Transport) getIdleConn(cm connectMethod) (pconn *persistConn, idleSince delete(t.idleConn, key) } else { // 2 or more cached connections; use the most - // recently used one. + // recently used one at the end. pconn = pconns[len(pconns)-1] t.idleConn[key] = pconns[:len(pconns)-1] } @@ -740,7 +740,9 @@ func (t *Transport) removeIdleConnLocked(pconn *persistConn) { if v != pconn { continue } - pconns[i] = pconns[len(pconns)-1] + // Slide down, keeping most recently-used + // conns at the end. + copy(pconns[i:], pconns[i+1:]) t.idleConn[key] = pconns[:len(pconns)-1] break } |
