summaryrefslogtreecommitdiff
path: root/src/mongo/db/exec
diff options
context:
space:
mode:
authorArun Banala <arun.banala@mongodb.com>2019-07-12 13:15:30 +0100
committerArun Banala <arun.banala@mongodb.com>2019-08-13 13:57:18 +0100
commit5105fa2377d3e86b2011691d5acbd8c531113929 (patch)
tree8640d2afd5537216d44f009dc656272577432bd1 /src/mongo/db/exec
parent796214e8426b3036f4eb4bdcc4af9d218589778f (diff)
downloadmongo-5105fa2377d3e86b2011691d5acbd8c531113929.tar.gz
SERVER-40382 Add a serverStatus metric to report plan cache memory consumption
Diffstat (limited to 'src/mongo/db/exec')
-rw-r--r--src/mongo/db/exec/plan_stats.h156
1 files changed, 156 insertions, 0 deletions
diff --git a/src/mongo/db/exec/plan_stats.h b/src/mongo/db/exec/plan_stats.h
index 938a633e342..9ec4d0b69a5 100644
--- a/src/mongo/db/exec/plan_stats.h
+++ b/src/mongo/db/exec/plan_stats.h
@@ -37,6 +37,7 @@
#include "mongo/db/index/multikey_paths.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/query/stage_types.h"
+#include "mongo/util/container_size_helper.h"
#include "mongo/util/time_support.h"
namespace mongo {
@@ -51,6 +52,8 @@ struct SpecificStats {
* Make a deep copy.
*/
virtual SpecificStats* clone() const = 0;
+
+ virtual uint64_t estimateObjectSizeInBytes() const = 0;
};
// Every stage has CommonStats.
@@ -66,6 +69,10 @@ struct CommonStats {
executionTimeMillis(0),
failed(false),
isEOF(false) {}
+
+ uint64_t estimateObjectSizeInBytes() const {
+ return filter.objsize() + sizeof(*this);
+ }
// String giving the type of the stage. Not owned.
const char* stageTypeStr;
@@ -121,6 +128,20 @@ struct PlanStageStats {
return stats;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return // Add size of each element in 'children' vector.
+ container_size_helper::estimateObjectSizeInBytes(
+ children,
+ [](const auto& child) { return child->estimateObjectSizeInBytes(); },
+ true) +
+ // Exclude the size of 'common' object since is being added later.
+ (common.estimateObjectSizeInBytes() - sizeof(common)) +
+ // Add 'specific' object size if exists.
+ (specific ? specific->estimateObjectSizeInBytes() : 0) +
+ // Add size of the object.
+ sizeof(*this);
+ }
+
// See query/stage_type.h
StageType stageType;
@@ -146,6 +167,10 @@ struct AndHashStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return container_size_helper::estimateObjectSizeInBytes(mapAfterChild) + sizeof(*this);
+ }
+
// How many entries are in the map after each child?
// child 'i' produced children[i].common.advanced RecordIds, of which mapAfterChild[i] were
// intersections.
@@ -169,6 +194,10 @@ struct AndSortedStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return container_size_helper::estimateObjectSizeInBytes(failedAnd) + sizeof(*this);
+ }
+
// How many results from each child did not pass the AND?
std::vector<size_t> failedAnd;
};
@@ -180,6 +209,10 @@ struct CachedPlanStats : public SpecificStats {
return new CachedPlanStats(*this);
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
+
bool replanned;
};
@@ -191,6 +224,11 @@ struct CollectionScanStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
+
+
// How many documents did we check against our filter?
size_t docsTested;
@@ -217,6 +255,10 @@ struct CountStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
+
// The result of the count.
long long nCounted;
@@ -243,6 +285,18 @@ struct CountScanStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return container_size_helper::estimateObjectSizeInBytes(
+ multiKeyPaths,
+ [](const auto& keyPath) {
+ // Calculate the size of each std::set in 'multiKeyPaths'.
+ return container_size_helper::estimateObjectSizeInBytes(keyPath);
+ },
+ true) +
+ keyPattern.objsize() + collation.objsize() + startKey.objsize() + endKey.objsize() +
+ indexName.capacity() + sizeof(*this);
+ }
+
std::string indexName;
BSONObj keyPattern;
@@ -280,6 +334,10 @@ struct DeleteStats : public SpecificStats {
return new DeleteStats(*this);
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
+
size_t docsDeleted = 0u;
};
@@ -293,6 +351,18 @@ struct DistinctScanStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return container_size_helper::estimateObjectSizeInBytes(
+ multiKeyPaths,
+ [](const auto& keyPath) {
+ // Calculate the size of each std::set in 'multiKeyPaths'.
+ return container_size_helper::estimateObjectSizeInBytes(keyPath);
+ },
+ true) +
+ keyPattern.objsize() + collation.objsize() + indexBounds.objsize() +
+ indexName.capacity() + sizeof(*this);
+ }
+
// How many keys did we look at while distinct-ing?
size_t keysExamined = 0;
@@ -329,6 +399,10 @@ struct EnsureSortedStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
+
// The number of out-of-order results that were dropped.
long long nDropped;
};
@@ -341,6 +415,10 @@ struct FetchStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
+
// Have we seen anything that already had an object?
size_t alreadyHasObj = 0u;
@@ -356,6 +434,10 @@ struct IDHackStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return indexName.capacity() + sizeof(*this);
+ }
+
std::string indexName;
// Number of entries retrieved from the index while executing the idhack.
@@ -387,6 +469,18 @@ struct IndexScanStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return container_size_helper::estimateObjectSizeInBytes(
+ multiKeyPaths,
+ [](const auto& keyPath) {
+ // Calculate the size of each std::set in 'multiKeyPaths'.
+ return container_size_helper::estimateObjectSizeInBytes(keyPath);
+ },
+ true) +
+ keyPattern.objsize() + collation.objsize() + indexBounds.objsize() +
+ indexName.capacity() + indexType.capacity() + sizeof(*this);
+ }
+
// Index type being used.
std::string indexType;
@@ -436,6 +530,10 @@ struct LimitStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
+
size_t limit;
};
@@ -445,6 +543,10 @@ struct MockStats : public SpecificStats {
SpecificStats* clone() const final {
return new MockStats(*this);
}
+
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
};
struct MultiPlanStats : public SpecificStats {
@@ -453,6 +555,10 @@ struct MultiPlanStats : public SpecificStats {
SpecificStats* clone() const final {
return new MultiPlanStats(*this);
}
+
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
};
struct OrStats : public SpecificStats {
@@ -463,6 +569,10 @@ struct OrStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
+
size_t dupsTested = 0u;
size_t dupsDropped = 0u;
};
@@ -475,6 +585,10 @@ struct ProjectionStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return projObj.objsize() + sizeof(*this);
+ }
+
// Object specifying the projection transformation to apply.
BSONObj projObj;
};
@@ -487,6 +601,10 @@ struct SortStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sortPattern.objsize() + sizeof(*this);
+ }
+
// What's our current memory usage?
size_t memUsage = 0u;
@@ -508,6 +626,10 @@ struct MergeSortStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sortPattern.objsize() + sizeof(*this);
+ }
+
size_t dupsTested = 0u;
size_t dupsDropped = 0u;
@@ -523,6 +645,10 @@ struct ShardingFilterStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
+
size_t chunkSkips;
};
@@ -534,6 +660,10 @@ struct SkipStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
+
size_t skip;
};
@@ -558,6 +688,11 @@ struct NearStats : public SpecificStats {
return new NearStats(*this);
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return container_size_helper::estimateObjectSizeInBytes(intervalStats) +
+ keyPattern.objsize() + indexName.capacity() + sizeof(*this);
+ }
+
std::vector<IntervalStats> intervalStats;
std::string indexName;
// btree index version, not geo index version
@@ -572,6 +707,10 @@ struct UpdateStats : public SpecificStats {
return new UpdateStats(*this);
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return objInserted.objsize() + sizeof(*this);
+ }
+
// The number of documents which match the query part of the update.
size_t nMatched;
@@ -596,6 +735,11 @@ struct TextStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return parsedTextQuery.objsize() + indexPrefix.objsize() + indexName.capacity() +
+ sizeof(*this);
+ }
+
std::string indexName;
// Human-readable form of the FTSQuery associated with the text stage.
@@ -615,6 +759,10 @@ struct TextMatchStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
+
size_t docsRejected;
};
@@ -626,6 +774,10 @@ struct TextOrStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
+
size_t fetches;
};
@@ -635,6 +787,10 @@ struct TrialStats : public SpecificStats {
return specific;
}
+ uint64_t estimateObjectSizeInBytes() const {
+ return sizeof(*this);
+ }
+
size_t trialPeriodMaxWorks = 0;
double successThreshold = 0;