MongoDB Fragmentation affect the Performance in WiredTiger
-
18-02-2021 - |
Question
Im using MongoDB 3.6 I have a huge number of fragmentation in my collections. 300+ GB on one collection. WiredTiger is the storage engine.
I know its bad for the OS and much wasted space. This affects the memory as well if we use MMAP engine. But I don't know how the fragmentation affects the WiredTiger?
Solution
It will be less efficient to fetch data if you have a lot of space available for reuse. However, that space could be reused if you continue to insert or update documents in the collection.
If you've dropped a significant amount of data (which sounds like ~300GB in one of your collections) you can reclaim space by either:
- re-syncing members of a replica set (recommended if you want to reclaim space from all collections)
- running the
compact
command (important caveat: this will block all operations for the database the operation is running on)
For either approach I would use rolling maintenance to maintain availability.
A resync would be the most effective option. The compact
command is riskier to run as a replica set member may become stale while running compact
offline (and require resync); this operation may also not be able to free as much disk space as a resync and needs to be run per collection.