fix(client): Improve keep-alive reuse strategy
The previous keep-alive strategy was to cycle connections in a round-robin style. However, that will always keep more connections around than are needed. This new strategy will allow extra connections to expire when only a few are needed. This is accomplished by prefering to reuse a connection that was just released to the pool over one that has been there for a long time.
This commit is contained in:
		| @@ -541,6 +541,7 @@ where C: Connect, | |||||||
|  |  | ||||||
|                 // Check all idle connections regardless of origin |                 // Check all idle connections regardless of origin | ||||||
|                 for (key, idle) in scope.idle_conns.iter_mut() { |                 for (key, idle) in scope.idle_conns.iter_mut() { | ||||||
|  |                     // Pop from the front since those are lease recently used | ||||||
|                     while let Some(ctrl) = idle.pop_front() { |                     while let Some(ctrl) = idle.pop_front() { | ||||||
|                         // Signal connection to close. An err here means the |                         // Signal connection to close. An err here means the | ||||||
|                         // socket is already dead can should be tossed. |                         // socket is already dead can should be tossed. | ||||||
| @@ -667,7 +668,9 @@ where C: Connect, | |||||||
|                                 let mut remove_idle = false; |                                 let mut remove_idle = false; | ||||||
|                                 let mut woke_up = false; |                                 let mut woke_up = false; | ||||||
|                                 if let Some(mut idle) = scope.idle_conns.get_mut(&key) { |                                 if let Some(mut idle) = scope.idle_conns.get_mut(&key) { | ||||||
|                                     while let Some(ctrl) = idle.pop_front() { |                                     // Pop from back since those are most recently used. Connections | ||||||
|  |                                     // at the front are allowed to expire. | ||||||
|  |                                     while let Some(ctrl) = idle.pop_back() { | ||||||
|                                         // err means the socket has since died |                                         // err means the socket has since died | ||||||
|                                         if ctrl.ready(Next::write()).is_ok() { |                                         if ctrl.ready(Next::write()).is_ok() { | ||||||
|                                             woke_up = true; |                                             woke_up = true; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user