Monitoring Tooling / Performance Analysis with Collection Stats

2:38
Sometimes we have to get even more granular and examine the specific collections. In this video, we'll use the d v dot collection dot stats helper method to provide information about a single collection since the last server restart. This is useful for assessing the performance of high traffic collections. To do this, we run the d b dot collection name dot stats method in the MongoDB shell. The output for collection stats is quite extensive, but we can also append a category name to the method to limit the results. Let's look at some useful categories to monitor, including storage size and index stats. Let's run collection stats on the orders collection. We can look at storage size to tell us how much disk space a specific collection is using. If a collection has a disproportionately large storage size, it might indicate inefficiencies in how we're storing data. In this example, we see that the storage size is surprisingly high. We might find that the orders collection contains a significant amount of historical order data that is rarely accessed. We should consider implementing a data archival strategy to move this older data to a less performance critical storage tier. The collection stats method also provides a breakdown of each index on the collection, including the total index size and index builds in progress. We can use this information to identify which indexes are being used effectively. In another example, after running collection stats on the products collection, we can see that the ratings one index is the largest index, consuming almost the entire total index size. We should investigate this index further to assess whether its large size is justified. To do that, we'll use index stats to see how often it's being used. Here, we're using index stats to learn more about the ratings one index. We can see that ratings one is never used, so it's not improving query performance. While you may be tempted to immediately drop this index to reclaim the space and resources it uses, MongoDB recommends that you use the hide index method to evaluate the impact of dropping an index before actually doing so. Here, we're using hide index to hide the index from the query planner so that it will not be used to support our queries. If after testing, we see that hiding the index has no impact on performance, we can use the drop index method to delete the index. Congratulations. In this video, we explore the d b dot collection dot stats method to examine specific collections, gaining insights into their storage characteristics and index usage for performance tuning.