Repository navigation
Track global cx limit in overload manager - #28202
Conversation
Signed-off-by: Kateryna Nezdolii <[email protected]>
|
@KBaichoo could you validate the suggested approach (for tracking global_cx_limit via overload manager)? If it looks good, i will continue with adding tests and deprecating the runtime flag. |
KBaichoo
left a comment
There was a problem hiding this comment.
At a high level the approach makes sense, thanks for working on this
| // Check if deprecated runtime flag `overload.global_downstream_max_connections` is configured | ||
| // simultaneously with downstream connections monitor in overload manager. | ||
| if (runtime_.threadsafeSnapshot()->get(GlobalMaxCxRuntimeKey)) { | ||
| ENVOY_LOG_MISC(warn, |
There was a problem hiding this comment.
Might make sense using ENVOY_LOG_ONCE macro for this (to avoid spamming) on every connection
Signed-off-by: Kateryna Nezdolii <[email protected]>
0864861 to
45d8591
Compare
Signed-off-by: Kateryna Nezdolii <[email protected]>
45d8591 to
5baade6
Compare
| #include "test/integration/integration.h" | ||
| #include "test/test_common/test_runtime.h" | ||
|
|
||
| using testing::InvokeWithoutArgs; |
|
There are still few TODOs and tests left, but implementation and all the main tests are ready. Since proactive resource monitors do not make use of overload actions (and entire overload manager mechanism of "subscribe for updates for this action"), we should either make it clear in user docs that action configuration is not needed for such monitor or introduce separate monitor type in api. |
59a2d45 to
bd33466
Compare
Signed-off-by: Kateryna Nezdolii <[email protected]>
There was a problem hiding this comment.
probably marked large due to amount of memory the test uses? You could likely pare it down similar to 3c84818#diff-47f3211970111aaa3c26392c795eb8bd7494049106c2b47693cd01bd621fcec8 if you want
bd33466 to
cf266a9
Compare
| @@ -0,0 +1,213 @@ | |||
| #include <unordered_map> | |||
|
@KBaichoo would this change benefit from measuring thread contention diff (main vs PR)? In old version we as well used atomic variable for tracking global downstream conns but with less synchronization (e.g. no CAS with explicit memory ordering when reading/writing to/from atomic) |
| ASSERT_TRUE(tcp_clients.back()->connected()); | ||
| } | ||
| }; | ||
| // todo (nezdolik) this should be logged once per each run (ipv4,ipv6), |
There was a problem hiding this comment.
@KBaichoo any ideas what the root cause can be here? Log macro uses static atomic variable for counting number of times logged, maybe it's not being reset across same test runs (but with different test params, e.g. ipv4/ipv6)
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
KBaichoo
left a comment
There was a problem hiding this comment.
Thanks for working on this, here's a pass
| @@ -0,0 +1,213 @@ | |||
| #include <unordered_map> | |||
There was a problem hiding this comment.
probably marked large due to amount of memory the test uses? You could likely pare it down similar to 3c84818#diff-47f3211970111aaa3c26392c795eb8bd7494049106c2b47693cd01bd621fcec8 if you want
| int64_t currentResourceUsage(OverloadProactiveResourceName resource_name) override { | ||
| const auto proactive_resource = proactive_resources_->find(resource_name); | ||
| if (proactive_resource == proactive_resources_->end()) { | ||
| ENVOY_LOG_MISC(warn, " {Failed to get resource usage for unknown proactive resource }"); |
There was a problem hiding this comment.
Given this is an enum class the resource name is likely not corrupted; this is more likely if the resource monitor isn't enabled?
| const auto proactive_resource = proactive_resources_->find(resource_name); | ||
| if (proactive_resource == proactive_resources_->end()) { | ||
| ENVOY_LOG_MISC(warn, " {Failed to get resource usage for unknown proactive resource }"); | ||
| return false; |
There was a problem hiding this comment.
yikes old c implicit conversion from bool -> int. Can we avoid somehow?
There was a problem hiding this comment.
Hah, I think that was a copy paste from another existing method and compilation silently passed so went unnoticed by me 🙂
| * Returns current resource usage (most recent read) tracked by monitor. | ||
| * @param name of resource monitor to check. | ||
| */ | ||
| virtual int64_t currentResourceUsage(OverloadProactiveResourceName resource_name) PURE; |
There was a problem hiding this comment.
Is this only going to be used for tests, as currently done in your integration test?
What do you think about const ProactiveResourceMonitor& getProactiveResourceMonitorForTest() or using a test peer freidn or similar ?
| initialize(); | ||
| } | ||
|
|
||
| std::string counterPrefix() { |
| num_downstream_conns_reached.Notify(); | ||
| } | ||
| // TODO(mattklein123): Do not use a real sleep here. Switch to events with waitFor(). | ||
| timeSystem().realSleepDoNotUseWithoutScrutiny(std::chrono::milliseconds(50)); |
There was a problem hiding this comment.
we will be sleeping on main thread (very bad)
There was a problem hiding this comment.
this review comment is not yet resolved
| // TODO(mattklein123): Do not use a real sleep here. Switch to events with waitFor(). | ||
| timeSystem().realSleepDoNotUseWithoutScrutiny(std::chrono::milliseconds(50)); | ||
| } | ||
| if (overload_state.currentResourceUsage( |
There was a problem hiding this comment.
don't understand why this is repeated twice in the same loop iteration
| if (overload_state.currentResourceUsage( | ||
| Server::OverloadProactiveResourceName::GlobalDownstreamMaxConnections) == | ||
| expected_connections) { | ||
| num_downstream_conns_reached.Notify(); |
There was a problem hiding this comment.
calling Notify() more that once on same notification is undefined behavior -- we should break out of here it we satisfied the condition
| }; | ||
| // TODO(nezdolik) this should be logged once per each run (ipv4,ipv6), | ||
| // but second run does not contain the log line even though logging code is hit. Some macro+test | ||
| // setup weirdness. |
There was a problem hiding this comment.
Yea I think it is as you pointed out due to the local static in the macro that this will just be logged once for the test.
I think we could run the test suite with just a IP version as it shouldn't be depedent on the IP version? (as one workaround).
|
/wait |
|
Thanks for review @KBaichoo, I will get back to it in 10 days after vacation. |
Signed-off-by: Kateryna Nezdolii <[email protected]>
KBaichoo
left a comment
There was a problem hiding this comment.
Windows CI still broken:
test/extensions/listener_managers/listener_manager/listener_manager_impl_test.cc(6106): error C2661: 'Envoy::Network::AcceptedSocketImpl::AcceptedSocketImpl': no overloaded function takes 3 arguments
/wait
Signed-off-by: Kateryna Nezdolii <[email protected]>
|
Apologies for delay, had to deal with a high priority task. Will wait if there are any other review comments left and then add the changelog. |
|
ping @RyanTheOptimist I think this is waiting for your input. |
| overload_state_->tryDeallocateResource( | ||
| Server::OverloadProactiveResourceName::GlobalDownstreamMaxConnections, 1); | ||
| } else { | ||
| ASSERT(global_accepted_socket_count_.load() > 0); |
There was a problem hiding this comment.
Hm. I'm slightly concerned about this going away. I've hit this ASSERT() in the past by buggingly changing some socket accounting. Do we need to remove this assert, even if we're using the overload manager generally?
There was a problem hiding this comment.
@RyanTheOptimist we could add similar assert in overload manager if branch above as extra layer of protection.
There was a problem hiding this comment.
I think that would be great.
There was a problem hiding this comment.
while this protection would be useful for programmatic errors, it will not cover all race cases, since check for current.load() > 0 reads atomic value in one place and then later tries to decrement it, there is still a chance of race condition (e.g. another worker threads have consumed all resource usage between assert and actual decrement). Overload manager logic has protection against this case: https://github.com/envoyproxy/envoy/blob/main/source/extensions/resource_monitors/downstream_connections/downstream_connections_monitor.cc#L41
There was a problem hiding this comment.
@RyanTheOptimist do you think assertion is still needed given that overload manager method would fail to deallocate resource if current value is <=0 ?
There was a problem hiding this comment.
Ah, I see. Ok, fair enough.
| ASSERT(global_accepted_socket_count_.load() > 0); | ||
| --global_accepted_socket_count_; | ||
| if (track_global_cx_limit_in_overload_manager_) { | ||
| overload_state_->tryDeallocateResource( |
There was a problem hiding this comment.
I would have expected to see a pair of calls, one in the constructor to allocate, and one in the destructor to deallocate. But clearly that's not the model we're using here. Can you say more?
There was a problem hiding this comment.
@RyanTheOptimist the explanation is in comments here: https://github.com/envoyproxy/envoy/pull/28202/files/1bfae38e6f7c34c04836fe235ba37b97f359f1f3#diff-27e11486c4836b7d7f730f65c6591cc6794ffb35a4273c148fd3cb54c9ba77cfR40
Instead of checking if it is possible to allocate resource/connection and then later in the code actually allocating the resource (like the old way does), we do a single call to overload manager in tcp listener which both checks for possibility of allocation and tries to allocate resource to reduce the possibility of race conditions.
There was a problem hiding this comment.
Ah! That makes sense. Mind adding a brief comment here explaining that it was allocated in TcpListenerImpl::rejectCxOverGlobalLimit()?
Oh, gosh, sorry. I thought it was waiting on you. Sorry about that! Added my comments. |
|
/wait |
Signed-off-by: Kateryna Nezdolii <[email protected]>
|
@RyanTheOptimist addressed review comments+added changelog, did not add assert statement yet, waiting for input. |
|
Looks like this needs a main merge. |
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
RyanTheOptimist
left a comment
There was a problem hiding this comment.
LGTM, assuming CI passes
|
/retest |
|
@RyanTheOptimist looks like all the checks are passing now |
- sync .bazelrc etc - update a warning msg due to envoyproxy/envoy#28202 Replaces #1027 Signed-off-by: Qin Qin <[email protected]>
Deprecate runtime key
overload.global_downstream_max_connectionsand track global active downstream connections limit in overload manager instead. The runtime key is still usable but using it yields deprecation warning. If both mechanisms are configured (overload resource monitor and runtime key), overload manager config will be preferred.Commit Message:
Additional Description:
Risk Level: High (change affects request hot path)
Testing: Done
Docs Changes: Done
Release Notes: TBD
Platform Specific Features: NA
Fixes #12419
Deprecated: Added deprecation note for runtime key
overload.global_downstream_max_connections