-
Notifications
You must be signed in to change notification settings - Fork 5.5k
stats: cache the results of the stats-matcher class. #6207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jmarantz
merged 19 commits into
envoyproxy:master
from
jmarantz:cache-stats-matcher-results
Mar 19, 2019
Merged
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fd51c80
cache the results of the stats-matcher class.
jmarantz c0b0747
Merge branch 'master' into cache-stats-matcher-results
jmarantz 9c3b3ef
Refactor the tests a bit, and move the main rejection-cache into the …
jmarantz a1bbd88
Use set of explicitly managed char* rather than set of std::string so…
jmarantz 43b10da
Test that accepts-all and rejects-all scenarios don't call rejects().
jmarantz b3f8d58
Merge branch 'master' into cache-stats-matcher-results
jmarantz 9fd2905
Add more comments around the lifetime & function of the ThreadLocalSt…
jmarantz 6185123
Add more comments, and disallow copy constructors for StringSet.
jmarantz 75f99b6
Merge branch 'master' into cache-stats-matcher-results
jmarantz 2bace0f
Remove extraneous duplicate test method that was not used.
jmarantz 03fa724
Merge branch 'master' into cache-stats-matcher-results
jmarantz 106ee9f
Merge branch 'master' into cache-stats-matcher-results
jmarantz 7865fdb
Address review comments.
jmarantz b6f4e28
Merge branch 'master' into cache-stats-matcher-results
jmarantz 49067d9
Add TODO to clean up the leak, and use unique_ptr to simplify memory …
jmarantz 7af5cf2
remove superfluous reserve().
jmarantz 0fffd53
Remove leak, using shared_ptr<std::string> to mirror the leak-avoidan…
jmarantz cfea59d
Add comments about why the set is implemented using a map.
jmarantz 95b2752
Use heterogenous flat_hash_set rather than a flat_hash_map<const char…
jmarantz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,13 +171,35 @@ class ThreadLocalStoreImpl : Logger::Loggable<Logger::Id::stats>, public StoreRo | |
| const Stats::StatsOptions& statsOptions() const override { return stats_options_; } | ||
|
|
||
| private: | ||
| template <class Stat> using StatMap = CharStarHashMap<Stat>; | ||
| friend class ThreadLocalStoreTestScope; | ||
|
|
||
| template <class Stat> using StatMap = ConstCharStarHashMap<Stat>; | ||
|
|
||
| struct TlsCacheEntry { | ||
| StatMap<CounterSharedPtr> counters_; | ||
| StatMap<GaugeSharedPtr> gauges_; | ||
| StatMap<TlsHistogramSharedPtr> histograms_; | ||
| StatMap<ParentHistogramSharedPtr> parent_histograms_; | ||
|
|
||
| // We keep a TLS cache of rejected stat names. This costs memory, but | ||
| // reduces runtime overhead running the matcher. Moreover, once symbol | ||
| // tables are integrated, rejection will need the fully elaborated string, | ||
| // and it we need to take a global symbol-table lock to run. We keep | ||
| // this char* map here in the TLS cache to avoid taking a lock to compute | ||
| // rejection. | ||
| // | ||
| // To avoid duplicate copies of stats, this map references const char* | ||
| // values from ThreadLocalStore::rejected_stats_, which is implemented | ||
| // as a absl::flat_hash_map<char*>, so the keys will be stable and safe | ||
| // to reference from other threads even as the hash-map resizes. | ||
| // | ||
| // Note that once a stat or rejected name enters into the TLS Cache, it | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we upgrade this to a TODO? IMO I would consider this a bug for a long running Envoy? WDYT?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed; done and reported #6306 |
||
| // remains in memory forever. This will effectively leak memory as scopes | ||
| // are dynamically removed from the configuration. This could be resolved by | ||
| // (a) using weak_ptr in the TLS cache and (b) proactively cleaning up | ||
| // expired items in each thread periodically. Alternatively, when a scope | ||
| // is removed, we could post() a cleanup request to each thread's TLS cache. | ||
| ConstCharStarHashSet rejected_stats_; | ||
| }; | ||
|
|
||
| struct CentralCacheEntry { | ||
|
|
@@ -223,7 +245,8 @@ class ThreadLocalStoreImpl : Logger::Loggable<Logger::Id::stats>, public StoreRo | |
| template <class StatType> | ||
| StatType& | ||
| safeMakeStat(const std::string& name, StatMap<std::shared_ptr<StatType>>& central_cache_map, | ||
| MakeStatFn<StatType> make_stat, StatMap<std::shared_ptr<StatType>>* tls_cache); | ||
| MakeStatFn<StatType> make_stat, StatMap<std::shared_ptr<StatType>>* tls_cache, | ||
| ConstCharStarHashSet* tls_rejected_stats, StatType& null_stat); | ||
|
|
||
| static std::atomic<uint64_t> next_scope_id_; | ||
|
|
||
|
|
@@ -254,8 +277,11 @@ class ThreadLocalStoreImpl : Logger::Loggable<Logger::Id::stats>, public StoreRo | |
| void mergeInternal(PostMergeCb mergeCb); | ||
| absl::string_view truncateStatNameIfNeeded(absl::string_view name); | ||
| bool rejects(const std::string& name) const; | ||
| bool rejectsAll() const { return stats_matcher_->rejectsAll(); } | ||
| template <class StatMapClass, class StatListClass> | ||
| void removeRejectedStats(StatMapClass& map, StatListClass& list); | ||
| bool checkAndRememberRejection(const std::string& name, ConstCharStarHashSet* tls_rejected_stats) | ||
| EXCLUSIVE_LOCKS_REQUIRED(lock_); | ||
|
|
||
| const Stats::StatsOptions& stats_options_; | ||
| StatDataAllocator& alloc_; | ||
|
|
@@ -267,6 +293,7 @@ class ThreadLocalStoreImpl : Logger::Loggable<Logger::Id::stats>, public StoreRo | |
| std::list<std::reference_wrapper<Sink>> timer_sinks_; | ||
| TagProducerPtr tag_producer_; | ||
| StatsMatcherPtr stats_matcher_; | ||
| CharStarSet rejected_stats_ GUARDED_BY(lock_); // See comment in TLSCacheEntry above. | ||
| std::atomic<bool> shutting_down_{}; | ||
| std::atomic<bool> merge_in_progress_{}; | ||
| Counter& num_last_resort_stats_; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.