From b75695e4e1d1b07c545f82ed31663dac248202cb Mon Sep 17 00:00:00 2001 From: Maddie Zechar Date: Wed, 23 Nov 2022 21:45:57 +0000 Subject: SERVER-71529 Add serverStatus metric for classic and SBE plan cache size --- src/mongo/db/query/classic_plan_cache.cpp | 1 + src/mongo/db/query/plan_cache.h | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src/mongo/db') diff --git a/src/mongo/db/query/classic_plan_cache.cpp b/src/mongo/db/query/classic_plan_cache.cpp index f4bbff1af2b..7789d894cb5 100644 --- a/src/mongo/db/query/classic_plan_cache.cpp +++ b/src/mongo/db/query/classic_plan_cache.cpp @@ -33,6 +33,7 @@ namespace mongo { CounterMetric planCacheTotalSizeEstimateBytes("query.planCacheTotalSizeEstimateBytes"); +CounterMetric planCacheEntries("query.planCacheTotalQueryShapes"); std::ostream& operator<<(std::ostream& stream, const PlanCacheKey& key) { stream << key.toString(); diff --git a/src/mongo/db/query/plan_cache.h b/src/mongo/db/query/plan_cache.h index d950b93f52f..a7db20699f3 100644 --- a/src/mongo/db/query/plan_cache.h +++ b/src/mongo/db/query/plan_cache.h @@ -50,6 +50,12 @@ class PlanCacheEntryBase; */ extern CounterMetric planCacheTotalSizeEstimateBytes; +/** + * Tracks the number of query shapes in the plan cache entries across all the collections. Each + * entry in the plan cache is a unique query shape. + */ +extern CounterMetric planCacheEntries; + /** * Information returned from a get(...) query. */ @@ -103,7 +109,7 @@ public: size_t works, DebugInfoType debugInfo) { // If the cumulative size of the plan caches is estimated to remain within a predefined - // threshold, then then include additional debug info which is not strictly necessary for + // threshold, then include additional debug info which is not strictly necessary for // the plan cache to be functional. Once the cumulative plan cache size exceeds this // threshold, omit this debug info as a heuristic to prevent plan cache memory consumption // from growing too large. @@ -155,6 +161,7 @@ public: ~PlanCacheEntryBase() { planCacheTotalSizeEstimateBytes.decrement(estimatedEntrySizeBytes); + planCacheEntries.decrement(1); } /** @@ -258,6 +265,8 @@ private: // Account for the object in the global metric for estimating the server's total plan cache // memory consumption. planCacheTotalSizeEstimateBytes.increment(estimatedEntrySizeBytes); + // Account for new entry in the plan cache. + planCacheEntries.increment(1); } // Ensure that PlanCacheEntryBase is non-copyable. -- cgit v1.2.1