forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 62
Fix connection reuse by delaying a poll cycle. #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jplevyak
merged 5 commits into
istio:release-1.1
from
jplevyak:istio-connection-reuse-fix
May 31, 2019
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0dedd11
Fix connection reuse by delaying a poll cycle.
jplevyak ccbf3a5
Delay 2 cycles and reenable independent of pending requests.
jplevyak 27f1810
Address comments.
jplevyak ec73477
Address formatting.
jplevyak c6ac813
Address comments.
jplevyak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,10 @@ ConnPoolImpl::ConnPoolImpl(Event::Dispatcher& dispatcher, Upstream::HostConstSha | |
| upstream_ready_timer_(dispatcher_.createTimer([this]() { onUpstreamReady(); })) {} | ||
|
|
||
| ConnPoolImpl::~ConnPoolImpl() { | ||
| while (!delayed_clients_.empty()) { | ||
| delayed_clients_.front()->codec_client_->close(); | ||
| } | ||
|
|
||
| while (!ready_clients_.empty()) { | ||
| ready_clients_.front()->codec_client_->close(); | ||
| } | ||
|
|
@@ -147,7 +151,12 @@ void ConnPoolImpl::onConnectionEvent(ActiveClient& client, Network::ConnectionEv | |
| } else if (!client.connect_timer_) { | ||
| // The connect timer is destroyed on connect. The lack of a connect timer means that this | ||
| // client is idle and in the ready pool. | ||
| removed = client.removeFromList(ready_clients_); | ||
| if (client.delayed_) { | ||
| client.delayed_ = 0; | ||
| removed = client.removeFromList(delayed_clients_); | ||
| } else { | ||
| removed = client.removeFromList(ready_clients_); | ||
| } | ||
| check_for_drained = false; | ||
| } else { | ||
| // The only time this happens is if we actually saw a connect failure. | ||
|
|
@@ -220,6 +229,20 @@ void ConnPoolImpl::onResponseComplete(ActiveClient& client) { | |
|
|
||
| void ConnPoolImpl::onUpstreamReady() { | ||
| upstream_ready_enabled_ = false; | ||
| auto it = delayed_clients_.begin(); | ||
| while (it != delayed_clients_.end()) { | ||
| ActiveClient& client = **it; | ||
| it++; // Move forward before moveBetweenLists which would invalidate 'it'. | ||
| client.delayed_--; | ||
| if (client.delayed_ == 0) { | ||
| ENVOY_CONN_LOG(debug, "moving from delay to ready", *client.codec_client_); | ||
| client.moveBetweenLists(delayed_clients_, ready_clients_); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you create another time here when
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| } | ||
| if (!delayed_clients_.empty()) { | ||
| upstream_ready_enabled_ = true; | ||
| upstream_ready_timer_->enableTimer(std::chrono::milliseconds(0)); | ||
| } | ||
| while (!pending_requests_.empty() && !ready_clients_.empty()) { | ||
| ActiveClient& client = *ready_clients_.front(); | ||
| ENVOY_CONN_LOG(debug, "attaching to next request", *client.codec_client_); | ||
|
|
@@ -234,7 +257,13 @@ void ConnPoolImpl::onUpstreamReady() { | |
|
|
||
| void ConnPoolImpl::processIdleClient(ActiveClient& client, bool delay) { | ||
| client.stream_wrapper_.reset(); | ||
| if (pending_requests_.empty() || delay) { | ||
| if (delay) { | ||
| ENVOY_CONN_LOG(debug, "moving to delay", *client.codec_client_); | ||
| // N.B. libevent does not guarantee ordering of events, so to ensure that the delayed client | ||
| // experiences a poll cycle before being made ready, delay for 2 event loops. | ||
| client.delayed_ = 2; | ||
jplevyak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| client.moveBetweenLists(busy_clients_, delayed_clients_); | ||
| } else if (pending_requests_.empty()) { | ||
| // There is nothing to service or delayed processing is requested, so just move the connection | ||
| // into the ready list. | ||
| ENVOY_CONN_LOG(debug, "moving to ready", *client.codec_client_); | ||
|
|
@@ -248,7 +277,7 @@ void ConnPoolImpl::processIdleClient(ActiveClient& client, bool delay) { | |
| pending_requests_.pop_back(); | ||
| } | ||
|
|
||
| if (delay && !pending_requests_.empty() && !upstream_ready_enabled_) { | ||
| if (!delayed_clients_.empty() && !upstream_ready_enabled_) { | ||
| upstream_ready_enabled_ = true; | ||
| upstream_ready_timer_->enableTimer(std::chrono::milliseconds(0)); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.