Repository navigation
Conversation
Signed-off-by: Kateryna Nezdolii <[email protected]>
|
There is bunch of duplicated code. Will refactor it after ensuring that whole thing works in tests. |
antoniovicente
left a comment
There was a problem hiding this comment.
Thanks for taking on this improvement to overload manager to allow for proactive checks when accepting new connections.
| void onSuccess(const ResourceUsage& usage) override; | ||
| void onFailure(const EnvoyException& error) override; | ||
|
|
||
| void update(uint64_t increment); |
There was a problem hiding this comment.
See #12419 (comment)
I would suggest changing the signature of this method to "bool tryAllocateResource()" and have it return true iff the attempt to allocate succeeded given current resource limits.
| virtual const OverloadActionState& getState(const std::string& action) PURE; | ||
| // On-demand recalculation of resource pressure and update of overload action state. | ||
| virtual void updateReactiveResource(const std::string& reactive_resource_name, | ||
| uint64_t increment) PURE; |
There was a problem hiding this comment.
I think that the idea behind the existing getState API is that most users will call getState once and save the reference for use from there on. updateReactiveResource seems to be called with the string argument a lot more often; consider passing in an enum with to select the resource name instead of a string for efficiency, or try to use a pattern similar to the getState one which returns a reference to the reactive resource which can then be updated directly.
| ActiveConnectionsResourceMonitor(uint64_t max_active_conns) | ||
| : ReactiveResourceMonitor(max_active_conns, 0){}; | ||
|
|
||
| void updateResourceUsage(uint64_t increment, Callbacks& callbacks) { |
There was a problem hiding this comment.
nit: There's a disagreement between the name of the first argument to this function in the base interface definition and the implementation here: It is curr_value in ReactiveResourceMonitor but increment here. The name of the first argument should be consistent between API definition and implementation.
| : ReactiveResourceMonitor(max_active_conns, 0){}; | ||
|
|
||
| void updateResourceUsage(uint64_t increment, Callbacks& callbacks) { | ||
| // Calling code will need to reset its current value after this. |
There was a problem hiding this comment.
how will this value be decremented or reset?
There was a problem hiding this comment.
as per your suggestion in the issue, i agree that we should introduce separate method like tryDeallocateResource that client code (for example TCP listener) will be calling when closing the socket.
| callbacks.onSuccess(usage); | ||
| } | ||
|
|
||
| void updateResourceUsage(Callbacks&) { NOT_IMPLEMENTED_GCOVR_EXCL_LINE; } |
There was a problem hiding this comment.
I think this use of NOT_IMPLEMENTED_GCOVR_EXCL_LINE suggests that ReactiveResourceMonitor is not a ResourceMonitor. Consider removing ResourceMonitor as a base class.
| ReactiveResourceMonitor(uint64_t max, uint64_t current) : max_(max), current_(current){}; | ||
| virtual ~ReactiveResourceMonitor() = default; | ||
| using ResourceMonitor::updateResourceUsage; | ||
| virtual void updateResourceUsage(uint64_t curr_value, Callbacks& callbacks) PURE; |
There was a problem hiding this comment.
Would be good to have comments for this new class and its API methods
|
|
||
| protected: | ||
| uint64_t max_; | ||
| std::atomic<uint64_t> current_; |
There was a problem hiding this comment.
I'm not finding examples of interface classes in the include/envoy directory that have data members. Could you move these data members to the implementation class and make currentResourceUsage/maxResourceUsage PURE ?
Signed-off-by: Kateryna Nezdolii <[email protected]>
|
pushing intermediate state to keep PR alive, i still need to apply bunch of review comments and add tests |
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
|
@antoniovicente cleaned up code a lot and reduced proactive checks to: Proactive checks now represent very different mechanism in OM and don't fit within OM model of registering for action, periodic resource pressure/action trigger recalculation and flushing updates etc. |
Signed-off-by: Kateryna Nezdolii <[email protected]>
antoniovicente
left a comment
There was a problem hiding this comment.
@antoniovicente cleaned up code a lot and reduced proactive checks to:
bool tryAllocateResource(OverloadReactiveResourceName resource_name /* enum val*/, uint64_t increment, ReactiveResourceUpdateCallbacks& cb); bool tryDeallocateResource(OverloadReactiveResourceName resource_name /* enum val*/, uint64_t decrement, ReactiveResourceUpdateCallbacks& cb);Proactive checks now represent very different mechanism in OM and don't fit within OM model of registering for action, periodic resource pressure/action trigger recalculation and flushing updates etc.
This methods will either be called from thread local object in worker threads or plugged into Dispatcher api.
Calling code would provide callback which will be invoked in OM upon updating the resource on next main dispatcher loop run.
I would like to know if this is an acceptable approach.
I'm having trouble understanding the proposed APIs, specifically OverloadManagerImpl::tryAllocateResource
| // uint64_t overflow, cannot allocate resource. | ||
| return false; | ||
| } else { | ||
| current_ += increment; |
There was a problem hiding this comment.
I think that it is possible for multiple threads to hit this increment concurrently after narrowly passing the checks above to verify that resource is available. Say that current_ is max_ - 1 as N threads attempt to increment by 1, all N of those threads may execute the current_.load() before the first thread gets to the increment, so at the end of these tryAllocateResource calls the value of current_ could be any value in [max_, max_ + N - 1].
The question how strict we want to be about this limit. Possible way to be more strict:
uint64_t new_val = (current_ += increment);
if (new_val >= max_) {
current_ -= increment;
return false;
}
return true;
There was a problem hiding this comment.
Double guard would also protect against potential race, though this version has more code:
if (current_.load() + inrement > max) {
return false;
} else {
//Guard against raice condition.
if (current_.load() + inrement <= max) {
current_ += increment;
return true;
}
return false;
}
|
|
||
| bool tryAllocateResource(uint64_t increment) { | ||
| auto curr_capacity = current_.load(); | ||
| if (std::numeric_limits<uint64_t>::max() - increment < curr_capacity) { |
There was a problem hiding this comment.
I think you meant to compare against max_ which contains the configured max number of connections, not std::numeric_limits<uint64_t>::max()
| auto curr_capacity = current_.load(); | ||
| if (decrement > curr_capacity) { | ||
| // There are not enough resources to deallocate. | ||
| return false; |
There was a problem hiding this comment.
It seems very unlikely for deallocate to fail unless the calling code is buggy. Consider making this an ASSERT instead.
|
|
||
| bool OverloadManagerImpl::tryAllocateResource(OverloadReactiveResourceName resource_name, | ||
| uint64_t increment, | ||
| ReactiveResourceUpdateCallbacks& cb) { |
There was a problem hiding this comment.
I'm having some trouble understanding how listeners would call this method. Some comments for the class method and interface method could help a lot.
I assume that tryAllocateResource can be called from any thread and would most likely be called from the thread associated with cb.dispatcher(). Having to go through a post for every accept would make it difficult to implement other desirable limits like accepting at most N connections per iteration of the event loop since all the accepts would happen from a possibly infinite chain of post calls.
There was a problem hiding this comment.
@antoniovicente this is most likely due to my knowledge gap, the only way i came up with is by posting on thread dispatcher from main thread.
| return true; | ||
| } | ||
|
|
||
| bool OverloadManagerImpl::tryAllocateResource(OverloadReactiveResourceName resource_name, |
There was a problem hiding this comment.
Can you document the return value of this method? At first glance it seemed to me that the return value should be true when allocation succeeds, but it seems to instead return true if the requested resource exists and this method was able to schedule the provided callback.
There was a problem hiding this comment.
@antoniovicente at first i was going to proceed with version that returns true if allocation succeeds:
bool tryAllocateResource(OverloadReactiveResourceName resource_name, uint64_t increment);
But then I could not come up with a way how to call this method from worker thread. I may be wrong, but in my understanding worker thread will not be able to call this method which runs on main thread without either blocking for result or doing it asynchronously (which is done by passing thread dispatcher and a callback).
There was a problem hiding this comment.
As discussed over slack, this method should be callable from workers. We just need to figure out how to make it available to workers.
| } | ||
| } else { | ||
| ENVOY_LOG(warn, " {Failed to allocate unknown reactive resource }"); | ||
| return false; |
There was a problem hiding this comment.
Should this branch call cb.dispatcher().post([&cb]() { cb.onFailure(); });
if so, I think the return value of this method could be removed.
|
@antoniovicente apologies for delays, am travelling this week. I will get back on this next Monday (may have little bit of time this weekend). |
Signed-off-by: Kateryna Nezdolii <[email protected]>
|
@antoniovicente applied review comments. We should agree on how |
antoniovicente
left a comment
There was a problem hiding this comment.
Removal of callbacks from the API seems like a big improvement. I took a quick look at the most recent commit, see comments below
| if (std::numeric_limits<uint64_t>::max() - increment < curr_capacity) { | ||
| // uint64_t overflow, cannot allocate resource. | ||
| uint64_t new_val = (current_ += increment); | ||
| if (new_val >= max_) { |
There was a problem hiding this comment.
I think this should be:
if (new_val > max_) {
| return false; | ||
| } else { | ||
| ASSERT(decrement <= current_.load()); | ||
| // Guard against race condition. |
There was a problem hiding this comment.
You still have a race between the current_.load() and the decrement.
I would consider making current_ atomic<int64_t> and RELEASE_ASSERT that the decrement doesn't go negative.
| std::string category() const override { return "envoy.resource_monitors"; } | ||
| }; | ||
|
|
||
| class ReactiveResourceMonitorFactory : public Config::TypedFactory { |
There was a problem hiding this comment.
Reactive -> Proactive
| return true; | ||
| } | ||
|
|
||
| bool OverloadManagerImpl::tryAllocateResource(OverloadReactiveResourceName resource_name, |
There was a problem hiding this comment.
As discussed over slack, this method should be callable from workers. We just need to figure out how to make it available to workers.
| return true; | ||
| } | ||
|
|
||
| bool tryDeallocateResource(uint64_t decrement) { |
There was a problem hiding this comment.
I'm not sure what caller code can/should if deallocation fails. If deallocation ever fails we have a serious logic error.
I guess an alternate API could involve a movable resource tracking object that releases the resource on destruction. That approach could reduce the risk of mismatched calls to allocate/deallocate the resource. That said, the resource tracking object approach may be overkill given that we expect this API to be used in a few places, one example being allocate just before creation of a server connection and de-allocation on server connection destruction.
As discussed over slack: Waiting for a round trip to the main thread from the workers will cause problems. The issue is that the main thread handles some very expensive operations like config reload and admin interface stats. These operations can take seconds to complete. |
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
Signed-off-by: Kateryna Nezdolii <[email protected]>
Signed-off-by: Kateryna Nezdolii <[email protected]>
|
@antoniovicente @alyssawilk i may need to split this huge PR into 2-3 parts for easier review:
|
Signed-off-by: Kateryna Nezdolii <[email protected]>
antoniovicente
left a comment
There was a problem hiding this comment.
@antoniovicente @alyssawilk i may need to split this huge PR into 2-3 parts for easier review:
- add proactive checks into overload manager
- add proactive downstream connections monitor (extension)
- deprecate runtime key for max downstream connections used by tcp listener and switch to overload manager proactive monitor.
Yes, it would be best to split this into smaller PRs if possible.
| /*/extensions/resource_monitors/injected_resource @eziskind @htuch | ||
| /*/extensions/resource_monitors/common @eziskind @htuch | ||
| /*/extensions/resource_monitors/fixed_heap @eziskind @htuch | ||
| /*/extensions/resource_monitors/downstream_connections @antoniovicente @mattklein123 |
There was a problem hiding this comment.
I would suggest also adding yourself to this list.
| #include "envoy/server/resource_monitor.h" | ||
| #include "envoy/server/resource_monitor_config.h" | ||
|
|
||
| #include "source/extensions/resource_monitors/downstream_connections/downstream_connections_monitor.h" |
There was a problem hiding this comment.
It would be best to move tests that depend on this extension to a new test/extensions file so it is possible to build envoy core without pulling in this extension.
| ":http_protocol_integration_lib", | ||
| "//envoy/network:filter_interface", | ||
| "//source/extensions/filters/network/tcp_proxy:config", | ||
| "//source/extensions/resource_monitors/downstream_connections:downstream_connections_monitor", |
There was a problem hiding this comment.
It is not legal to depend on source/extensions from tests that are not associated with the extension in question.
adisuissa
left a comment
There was a problem hiding this comment.
IIUC this is going to be split into multiple PRs, so feel free to make the API change in one of these PRs.
|
|
||
| // TODO(nezdolik) Add description | ||
| message DownstreamConnectionsConfig { | ||
| uint64 max_active_downstream_connections = 1 [(validate.rules).uint64 = {gt: 0}]; |
There was a problem hiding this comment.
Please also add comments to the field, and specify default value.
|
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
|
This pull request has been automatically closed because it has not had activity in the last 37 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
|
heaps up, am now actively working on splitting this PR into multiple ones, this is not forgotten |
Signed-off-by: Kateryna Nezdolii [email protected]
For an explanation of how to fill out the fields, please see the relevant section
in PULL_REQUESTS.md
Commit Message:
Additional Description: This PR contains addition of proactive checks into overload manager/thread local state, new proactive resource monitor for active downstream connections and plugging of proactive checks into tcp listener (for rejecting connections).
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Deprecated:]
[Optional API Considerations:]