add deferred_creation util into stats (#27899)

Commit Message:
With lots of clusters and route-tables in a cloud proxy, we are seeing tons of RAM been spent on stats while most of the stats are never inc-ed due to traffic pattern(or long tail). We are thinking that we can lazy init cluster stats() so that the RAM is only allocated when it's required.

To achieve that we need to have finer grained stats group, e.g. configUpdateStats() are frequently updated by config management server, while upstream_xxx are only required when there is traffic for the cluster, for this sub-group we can save RAM by lazy init it.

Introduce a new stats utility in this PR such that the nested StatsStruct is only instantiated when any of "->" or "*xx." operator is used.

Cribbed from PR #23921
Please see that PR for how it is used.

Additional Description:
Risk Level: LOW,utility lib not used yet.
Testing: unit test and speed test.
Docs Changes:
Release Notes:
Platform Specific Features:

Signed-off-by: Xin Zhuang <stevenzzz@google.com>

Mirrored from https://github.com/envoyproxy/envoy @ 7801df6af9000ae31bdd89b080e0d797501cbd18
main
update-envoy[bot] 1 year ago
parent 793eb3677a
commit d18dbfd3f5
  1. 18
      envoy/config/bootstrap/v3/bootstrap.proto

@ -41,7 +41,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;
// <config_overview_bootstrap>` for more detail.
// Bootstrap :ref:`configuration overview <config_overview_bootstrap>`.
// [#next-free-field: 39]
// [#next-free-field: 40]
message Bootstrap {
option (udpa.annotations.versioning).previous_message_type =
"envoy.config.bootstrap.v2.Bootstrap";
@ -124,6 +124,18 @@ message Bootstrap {
LogFormat log_format = 1;
}
message DeferredStatOptions {
// When the flag is enabled, Envoy will lazily initialize a subset of the stats (see below).
// This will save memory and CPU cycles when creating the objects that own these stats, if those
// stats are never referenced throughout the lifetime of the process. However, it will incur additional
// memory overhead for these objects, and a small increase of CPU usage when a at least one of the stats
// is updated for the first time.
// Groups of stats that will be lazily initialized:
// - Cluster traffic stats: a subgroup of the :ref:`cluster statistics <config_cluster_manager_cluster_stats>`
// that are used when requests are routed to the cluster.
bool enable_deferred_creation_stats = 1;
}
reserved 10, 11;
reserved "runtime";
@ -186,6 +198,10 @@ message Bootstrap {
// Optional set of stats sinks.
repeated metrics.v3.StatsSink stats_sinks = 6;
// Options to control behaviors of deferred creation compatible stats.
// [#not-implemented-hide:]
DeferredStatOptions deferred_stat_options = 39;
// Configuration for internal processing of stats.
metrics.v3.StatsConfig stats_config = 13;

Loading…
Cancel
Save