-
Notifications
You must be signed in to change notification settings - Fork 5.5k
thrift: supported setting max requests for per downstream connection #15125
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
Changes from 4 commits
f8538bf
cb664b0
3446082
aa038d4
7f5b510
1c99671
d3e44e3
fa47f36
8a832d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
|
Member
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. not needed anymore i think
Member
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. 👍 yes, it is not needed. I just forget to remove it. |
||
| #include <map> | ||
| #include <string> | ||
|
|
||
|
|
@@ -82,6 +83,7 @@ class ConfigImpl : public Config, | |
| ProtocolPtr createProtocol() override; | ||
| Router::Config& routerConfig() override { return *this; } | ||
| bool payloadPassthrough() const override { return payload_passthrough_; } | ||
| uint64_t maxRequestsPerConnection() const override { return max_requests_per_connection_; } | ||
|
|
||
| private: | ||
| void processFilter( | ||
|
|
@@ -96,6 +98,8 @@ class ConfigImpl : public Config, | |
|
|
||
| std::list<ThriftFilters::FilterFactoryCb> filter_factories_; | ||
| const bool payload_passthrough_; | ||
|
|
||
| uint64_t max_requests_per_connection_{}; | ||
| }; | ||
|
|
||
| } // namespace ThriftProxy | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,12 +12,21 @@ namespace Extensions { | |
| namespace NetworkFilters { | ||
| namespace ThriftProxy { | ||
|
|
||
| namespace { | ||
| // Translate zero to UINT64_MAX so that the zero/unlimited case doesn't | ||
| // have to be handled specially. | ||
| uint64_t translateZeroToUnlimited(uint64_t limit) { | ||
| return (limit != 0) ? limit : std::numeric_limits<uint64_t>::max(); | ||
| } | ||
| } // namespace | ||
|
|
||
| ConnectionManager::ConnectionManager(Config& config, Random::RandomGenerator& random_generator, | ||
| TimeSource& time_source) | ||
| : config_(config), stats_(config_.stats()), transport_(config.createTransport()), | ||
| protocol_(config.createProtocol()), | ||
| decoder_(std::make_unique<Decoder>(*transport_, *protocol_, *this)), | ||
| random_generator_(random_generator), time_source_(time_source) {} | ||
| random_generator_(random_generator), time_source_(time_source), | ||
| remaining_streams_(translateZeroToUnlimited(config.maxRequestsPerConnection())) {} | ||
|
|
||
| ConnectionManager::~ConnectionManager() = default; | ||
|
|
||
|
|
@@ -55,6 +64,11 @@ void ConnectionManager::dispatch() { | |
| return; | ||
| } | ||
|
|
||
| if (requests_overflow_) { | ||
| ENVOY_CONN_LOG(debug, "thrift filter requests overflow", read_callbacks_->connection()); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| bool underflow = false; | ||
| while (!underflow) { | ||
|
|
@@ -139,6 +153,9 @@ void ConnectionManager::continueDecoding() { | |
|
|
||
| void ConnectionManager::doDeferredRpcDestroy(ConnectionManager::ActiveRpc& rpc) { | ||
| read_callbacks_->connection().dispatcher().deferredDelete(rpc.removeFromList(rpcs_)); | ||
| if (requests_overflow_ && rpcs_.empty()) { | ||
| read_callbacks_->connection().close(Network::ConnectionCloseType::FlushWrite); | ||
| } | ||
| } | ||
|
|
||
| void ConnectionManager::resetAllRpcs(bool local_reset) { | ||
|
|
@@ -404,6 +421,13 @@ void ConnectionManager::ActiveRpc::finalizeRequest() { | |
|
|
||
| parent_.stats_.request_.inc(); | ||
|
|
||
| parent_.remaining_streams_--; | ||
| if (parent_.remaining_streams_ == 0) { | ||
| parent_.read_callbacks_->connection().readDisable(true); | ||
| parent_.requests_overflow_ = true; | ||
|
Member
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. can we add a stat for this and increment it here?
Member
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. Get. |
||
| parent_.stats_.downstream_cx_max_requests_.inc(); | ||
| } | ||
|
|
||
| bool destroy_rpc = false; | ||
| switch (original_msg_type_) { | ||
| case MessageType::Call: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ class Config { | |
| virtual ProtocolPtr createProtocol() PURE; | ||
| virtual Router::Config& routerConfig() PURE; | ||
| virtual bool payloadPassthrough() const PURE; | ||
| virtual uint64_t maxRequestsPerConnection() const PURE; | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -272,6 +273,10 @@ class ConnectionManager : public Network::ReadFilter, | |
| bool stopped_{false}; | ||
| bool half_closed_{false}; | ||
| TimeSource& time_source_; | ||
|
|
||
| // The maximum number of requests remaining to be processed on the current connection. | ||
| uint64_t remaining_streams_{}; | ||
|
Member
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. Can we do this the other way around? Having a counter of seen requests and a the limit in a separate var? E.g.: If max_requests_ is 0, there are no limits. I rather avoid depending on
Member
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. I have no objection. The reason for choosing current method is to reduce one
Member
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. But it should be ok. |
||
| bool requests_overflow_{false}; | ||
| }; | ||
|
|
||
| } // namespace ThriftProxy | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.