envoyproxy / envoyproxy/envoy

[stats]: lazy init stats to save RAM (and CPU)

Open
#23,575 4 comments 0 reactions 0 assignees View on GitHub
area/stats enhancement no stalebot
Dominant language
C++
Stars
28.9k
Forks
5.6k
Avg merge
1d 20h
Merged PRs (30d)
437

Description

*Title*: stats: lazy init stats to save RAM (and CPU)

*Description*:

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.

Here is an example of cluster stats, when there is no traffic, Envoy is still paying the RAM cost to hold all the 0 stats, as well as the CPU that's burnt on collecting such stats.

![6H22NSL5KWcwJH8](https://user-images.githubusercontent.com/3444556/196794847-bfe7e26c-21e0-46f4-800d-8fc4fa177245.png)

[optional *Relevant Links*:]
>Any extra documentation required to understand the issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.