While the automatic padding factor is a good first-order approximation for determining data growth, it's not adequate for some stores in which the application can know in advance how large a document might grow to and in which growth has serious performance implications.
In this case, MongoDB suggests adding manual padding.
It would be nice if MongoDB supported this explicit padding naturally as part of the insert query. The insert (and probably upsert and save) operations would be extended with a 'padding_bytes' and/or a 'min_allocation_bytes' parameter (or similar) such that the insert operation would allocate a minimum amount of space for that document. For example::
# ensure the doc is saved with a total allocation no less than 512 bytes db.my_items.insert({foo: "bar"}, {padding_bytes: 512})
It appears that currently the insert operation doesn't accept any optional parameters, so this change would require extending that signature or otherwise providing such a mechanism.
The advantages of this technique over the prescribed technique are clear:
1) Only one round trip to save the document.
2) Dummy data doesn't need to be constructed nor transmitted.
3) If 'min_allocation_bytes' is used, the total allocation is explicit rather than dependent on the size of the essential document.
4) The clients' usage is much simpler.
- duplicates
-
SERVER-3564 new $archive update operator to reduce storage waste
- Closed
- related to
-
SERVER-1810 ability to set minimum allocation size per collection
- Closed