Question

I have a collection with ~280000 items. A few weeks ago I noticed that the paddingFactor was quite high,

> db.products.stats().paddingFactor
1.409999999998178

When I looked today, it have decreased significantly:

> db.products.stats().paddingFactor
1.0099999999978637

I was under the impression that I've to run compact() to decrease the padding factor, am I wrong? Does mongodb execute this by itself regularly ? Or how come it can decrease "by itself"?

Was it helpful?

Solution

The padding factor is recalculated all the time (on a sampled basis, so not for every operation, but for every n th operation, n currently being 4) to ensure a good balance of storage fragmentation vs. storage overhead. If you're doing a lot of updates that require documents to grow, the padding factor will increase. If you perform a lot of inserts (where the documents fits per definition), the paddingFactor will slowly decrease towards 1.0 again.

Doing a compact() will remove the existing padding of all documents and trim all objects to their actual size, which can be what you want, but which can also lead to trouble if you blindly apply this to collection where a lot of growing happens.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top