stats: Use inlined primitive counter and gauge for HostStats in order to reduce per-host memory usage.#8216
Conversation
…uce per-host memory usage. Signed-off-by: Antonio Vicente <avd@google.com>
Signed-off-by: Antonio Vicente <avd@google.com>
|
@antoniovicente qq: are you still planning on having an option to completely remove host stats (or have them be canary only, a % of hosts, etc.)? Or is this good enough for your current case? |
Stats overhead is down to 96 bytes per host which seems good enough for now. I'll likely start looking into improvements in other areas next, including possibly thinking about how to share upstream connections across serving threads or optimize route selection. |
Cool sounds great. |
jmarantz
left a comment
There was a problem hiding this comment.
This is awesome stuff. I have one minor suggestion and a potential behavior difference to check.
Signed-off-by: Antonio Vicente <avd@google.com>
Signed-off-by: Antonio Vicente <avd@google.com>
jmarantz
left a comment
There was a problem hiding this comment.
lgtm modulo minor comments/prefs.
…tats Signed-off-by: Antonio Vicente <avd@google.com>
…map<string,STAT> to vector<pair<string_view,STAT>> Signed-off-by: Antonio Vicente <avd@google.com>
…emory usage in non golden build configurations. Signed-off-by: Antonio Vicente <avd@google.com>
jmarantz
left a comment
There was a problem hiding this comment.
just a few minor suggestions; up to you.
Signed-off-by: Antonio Vicente <avd@google.com>
Signed-off-by: Antonio Vicente <avd@google.com>
…Gauge Signed-off-by: Antonio Vicente <avd@google.com>
Signed-off-by: Antonio Vicente <avd@google.com>
Signed-off-by: Antonio Vicente <avd@google.com>
jmarantz
left a comment
There was a problem hiding this comment.
@envoyproxy/senior-maintainers for another pass (need non-googler)
mattklein123
left a comment
There was a problem hiding this comment.
Thanks this is awesome. Quick question.
/wait-any
| Stats::StatNameManagedStorage locality_zone_stat_name_; | ||
| Stats::IsolatedStoreImpl stats_store_; | ||
| HostStats stats_; | ||
| mutable HostStats stats_; |
There was a problem hiding this comment.
qq: what was the reasoning behind the mutable and const to non-const switch here? Presumably because we were previously violating the constness anyway and this makes it more explicit? It would be pretty cool to not do this. I assume you looked and it's not easy to fix this right now because we modify stats already though a const host?
There was a problem hiding this comment.
Before this change HostStats contained non-const references to counter objects, while now it holds the counters themselves as members.
Consider host.stats().rq_success_.inc() before and after that change:
before: The HostStats returned by Host::stats is const, but rq_success_ is not const so the call to inc() is fine.
after: if HostStats is const its members are also const, attempts to call inc() on the const counter object will fail compilation.
We could instead make the counters and gauges inside HostStats as mutable. Making the stats() method non-const seems challenging due to widespread use of HostConstSharedPtr in load balancers. Calls to stats() on a HostConstSharedPtr followed by increment calls on a counter are widespread, see source/common/router/router.cc for some examples.
Should we consider switch from std::shared_ptr to std::shared_ptr as the primary way to reference Host objects in order to avoid use of mutable?
There was a problem hiding this comment.
Should we consider switch from std::shared_ptr to std::shared_ptr as the primary way to reference Host objects in order to avoid use of mutable?
I'm not sure what the best thing to do here is. This is a pre-existing problem elsewhere, so it's not something you introduced, it's just never thrilled me that we ended up here and I wanted to make sure it's the same issue. I would say let's just merge this and we can consider further cleanups later if you are so inclined?
There was a problem hiding this comment.
Sounds good. Thanks!
… to reduce per-host memory usage. (envoyproxy#8216) Signed-off-by: Antonio Vicente <avd@google.com>
Description: Introduce low memory overhead counter and gauges classes for use in HostStats. These new isolated stats objects are meant to be instantiated inline on stats structs rather than created by name from a stats storage and ref counted. Low-memory stats objects are important in the case of HostStats due to the large number of hosts that a proxy can end up talking to.
Risk Level: Low
Testing: unit test
Docs Changes: n/a
Release Notes: n/a
Fixes #7525