Skip to content

Commit

Permalink
opt network
Browse files Browse the repository at this point in the history
  • Loading branch information
chenchen.ccqy66 committed Apr 27, 2022
1 parent 826f6c8 commit 3442bf2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions bfe_http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,16 @@ func (t *Transport) putIdleConn(pconn *persistConn) bool {
if t.idleConn == nil {
t.idleConn = make(map[string][]*persistConn)
}
// if t.idleConn's length >= t.maxIdleConnsPerHost, will close the oldest connection.
// when a TCP socket is unused for a while the congestion window is reset, and next time it is used, it will
// be in slow start mode. So a recently used connection is likely to have a larger window size, and allow
// faster transmission, than one which has been idle for a long time.
if len(t.idleConn[key]) >= max {
oldest := t.idleConn[key][0]
t.idleConn[key] = append(t.idleConn[key][1:], pconn)
t.idleMu.Unlock()
pconn.close()
return false
oldest.close()
return true
}
for _, exist := range t.idleConn[key] {
if exist == pconn {
Expand Down

0 comments on commit 3442bf2

Please sign in to comment.