MongoDB space usage

The following information outlines how ObjectRocket calculates space usage for all MongoDB instances, including determining how much space your MongDB instance is using and an explanation of associated charges.

Calculating space for MongoDB plans

On the ObjectRocket MongoDB platform, a plan represents the maximum amount of data you can store on a MongoDB instance without taking any action. When building a MongoDB instance for the first time, you’re required to choose a size in incrementing blocks, such as 5 GB, 20 GB, 50 GB, or others. Because you’ll know exactly how the capacity increases as you grow, this size selection makes it easy to plan out scaling in advance.

If the MongoDB instance is sharded, the plan size is multiplied by the number of shards currently attached to the instance to give you the maximum amount of space available. If the MongoDB instance is a replica set, the plan size is the maximum available storage space.

The following formula shows how to calculate the maximum gigabytes in plan (mgp) for all MongoDB instance types:

mgp = (SizeofPlan in GBs) * n (where n is the number of shards)

By using this formula, a 5 GB sharded instance with 3 shards has a mgp of 15 GB.

All data used for determining space usage is pulled directly from MongoDB by using db.stats() across each individual database on each shard, which differs slightly for WiredTiger or MMAPv1.

WiredTiger

If the MongoDB instance is running on WiredTiger, two values are used from the dbStats output, dbStats.storageSize (dss) and dbStats.indexSize (dis). Using these values is necessary because WiredTiger stores data and indexes in separate files.

The following formula shows how space consumed is summarized for WiredTiger per database:

dbs1 + dbs2 + … + dbsn = Document Storage for instance (ids)
dbi1 + dbi2 + … + dbin = Index Storage for instance (iis)
dbs + dbi = Storage used for a single database (sdb)
sdb1 + sdb2 + … + sdbn = Aggregated consumed space within Replica Set (asc)

After calculating how much space each database and index use, ObjectRocket uses that information to find out how much space a MongoDB instance is using with the following formula:

asc1 + asc2 + … + ascn = Total consumed space on all replica sets (tsc)

_images/wiredtiger_spaceusage.png

MMAPv1

MMAPv1 stores data and indexes on the same files, so the only important output is dbStats.fileSize. While MMAPv1 logs both dbStats.storageSize and dbStats.indexSize, this information is only useful in roughly determining the level of fragmentation within the MongoDB instance.

_images/mmap_spaceusage.png

What is not calculated

ObjectRocket fully manages MongoDB for you, including the pieces that create storage amplification like replication, journaling, namespace file, and ObjectRocket administrative databases. The following space calculations aren’t necessary:

  • Oplog size (local)
  • Journal size
  • Namespace size
  • The admin and config databases

If you have any questions, contact the Support team.