Skip to content

Fragmented / Bloated or whatever it is called - DocumentDB

-1

Hi,

I am a total newbie to DocumentDB or MongoDB. Unfortunately, need to check on everything that get send my way :-) One of our clients thinks the DocumentDB is 'bloated', fragmented or has lots of wasted space and maybe the reason why the application is degrading.

Version and Size information below.

rs0:PRIMARY> db.version()
4.0.0
rs0:PRIMARY> db.runCommand({getEngineVersion: 1})
{
        "engineVersion" : "2.0.10898",
        "ok" : 1,
        "operationTime" : Timestamp(1732071471, 1)
}
rs0:PRIMARY>

rs0:PRIMARY> db.stats()
{
        "db" : "[MyDB]",
        "collections" : 28,
        "objects" : 44452673,
        "storageSize" : 151448076288,
        "indexes" : 135,
        "indexSize" : 242403483648,
        "fileSize" : 393851559936,
        "ok" : 1,
        "operationTime" : Timestamp(1732072484, 1)
}

Is there a quick way to check if there really is some wasted space that may require some reorg of some sort to improve performance in some way? I've been doing a lot of reading and browsing around but can't find what am looking for. At the moment, I am interested in finding out whether there is 'considerable' waste of space or fragmentation anywhere.

Any guidance will be much appreciated. Thanks in advance.

P.S.: I wish I can get db.stats to show in GB :( Can't run aws cli commands, can only use mongo/mongosh.

asked 2 years ago502 views

1 Answer
0

Based on the information provided, it's not immediately clear that your Amazon DocumentDB instance is significantly "bloated" or fragmented. However, we can analyze the stats you've provided to give you a better understanding of your database's current state.

First, let's break down the db.stats() output:

  1. Total objects: 44,452,673
  2. Storage size: ~141 GB (151,448,076,288 bytes)
  3. Index size: ~226 GB (242,403,483,648 bytes)
  4. File size: ~367 GB (393,851,559,936 bytes)

The file size represents the total allocated space for your database, including data, indexes, and some overhead. The difference between the file size and the sum of storage size and index size is about 0.3 GB, which is not a significant amount of wasted space.

It's worth noting that the index size is larger than the storage size, which could indicate that you have a lot of indexes. While indexes improve query performance, they also consume space and can slow down write operations. You might want to review your indexing strategy to ensure you're not over-indexing.

Regarding fragmentation, Amazon DocumentDB is designed to handle this automatically. Unlike traditional MongoDB, DocumentDB uses a distributed, fault-tolerant, self-healing storage system that continuously works to minimize fragmentation. It doesn't require manual defragmentation or compaction operations.

If you're experiencing performance degradation, it may not be due to "bloat" or fragmentation. Instead, consider looking into other factors such as:

  1. Query performance: Analyze slow queries and optimize them if necessary.
  2. Instance size: Ensure your instance type has sufficient resources for your workload.
  3. Connection management: Check if you're hitting connection limits.
  4. Monitoring metrics: Use Amazon CloudWatch to monitor key metrics like CPU utilization, IOPS, and network throughput.

To get db.stats() to show in GB, you can divide the byte values by 1024^3 in your application code or use a calculator.

If you want to dive deeper into performance analysis, you can use Amazon DocumentDB's integration with Performance Insights, which provides a detailed view of database performance.

Remember, Amazon DocumentDB is designed to handle storage management automatically, so manual reorganization or compaction is typically not necessary or possible as it is with traditional MongoDB deployments.
Sources
Monitoring Amazon DocumentDB with CloudWatch - Amazon DocumentDB
What is Amazon DocumentDB (with MongoDB compatibility) - Amazon DocumentDB
Amazon DocumentDB architecture - Getting Started with Amazon DocumentDB (with MongoDB Compatibility)

answered 2 years ago

EXPERT

reviewed 2 years ago

  • Thanks for your response. I will check on how things progresses. Yes, there is a lot of indexes.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.