Chunk Size in MongoDB

 

When the first mongos connects to a set of config servers, it initializes the sharded cluster with a default chunk size of 64 megabytes.
This default chunk size works well for most deployments; however, if you notice that automatic migrations have more I/O than your hardware can handle, you may want to reduce the chunk size.
For automatic splits and migrations, a small chunk size leads to more rapid and frequent migrations.
The allowed range of the chunk size is between 1 and 1024 megabytes, inclusive.

To modify the chunk size, use the following procedure:
——————————————————————————–

Connect to any mongos in the cluster using the mongo shell.
Issue the following command to switch to the Config Database:

Issue the following save() operation to store the global chunk size configuration value

mongos> use config
switched to db config
mongos> 
mongos> db.settings.find()
{ "_id" : "chunksize", "value" : 64 }
mongos> 
mongos> db.settings.save( { _id:"chunksize", value: 128 } )
mongos> 
mongos> db.settings.find()
{ "_id" : "chunksize", "value" : 128 }
mongos> 
mongos> 
mongos> 
mongos> 
mongos> show collections
changelog
chunks
collections
databases
lockpings
locks
mongos
settings
shards
system.indexes
tags
version
mongos> 
mongos> db.chunks.find()
{ "_id" : "dbversity.nosql-mongodb_MinKey", "lastmod" : Timestamp(5, 0), "lastmodEpoch" : ObjectId("545b234f7532482f2245ea88"), "ns" : "dbversity.nosql", "min" : { "mongodb" : { "$minKey" : 1 } }, "max" : { "mongodb" : 0.06472490564920008 }, "shard" : "rs1" }
{ "_id" : "dbversity.rdbms-oracle_MinKey", "lastmod" : Timestamp(7, 1), "lastmodEpoch" : ObjectId("545b23547532482f2245ea89"), "ns" : "dbversity.rdbms", "min" : { "oracle" : { "$minKey" : 1 } }, "max" : { "oracle" : 0.0412344322539866 }, "shard" : "rs2" }
{ "_id" : "dbversity.newsql-memsql_MinKey", "lastmod" : Timestamp(6, 0), "lastmodEpoch" : ObjectId("545b23597532482f2245ea8b"), "ns" : "dbversity.newsql", "min" : { "memsql" : { "$minKey" : 1 } }, "max" : { "memsql" : 0.028616901952773333 }, "shard" : "rs1" }
{ "_id" : "dbversity.nosql-mongodb_0.06472490564920008", "lastmod" : Timestamp(3, 1), "lastmodEpoch" : ObjectId("545b234f7532482f2245ea88"), "ns" : "dbversity.nosql", "min" : { "mongodb" : 0.06472490564920008 }, "max" : { "mongodb" : 0.999929167330265 }, "shard" : "rs1" }
{ "_id" : "dbversity.nosql-mongodb_0.999929167330265", "lastmod" : Timestamp(4, 0), "lastmodEpoch" : ObjectId("545b234f7532482f2245ea88"), "ns" : "dbversity.nosql", "min" : { "mongodb" : 0.999929167330265 }, "max" : { "mongodb" : { "$maxKey" : 1 } }, "shard" : "rs1" }
{ "_id" : "dbversity.rdbms-oracle_0.0412344322539866", "lastmod" : Timestamp(5, 1), "lastmodEpoch" : ObjectId("545b23547532482f2245ea89"), "ns" : "dbversity.rdbms", "min" : { "oracle" : 0.0412344322539866 }, "max" : { "oracle" : 0.5 }, "shard" : "rs2" }
{ "_id" : "dbversity.rdbms-oracle_0.9998706732876599", "lastmod" : Timestamp(7, 0), "lastmodEpoch" : ObjectId("545b23547532482f2245ea89"), "ns" : "dbversity.rdbms", "min" : { "oracle" : 0.9998706732876599 }, "max" : { "oracle" : { "$maxKey" : 1 } }, "shard" : "rs3" }
{ "_id" : "dbversity.newsql-memsql_0.02861690195277333", "lastmod" : Timestamp(7, 0), "lastmodEpoch" : ObjectId("545b23597532482f2245ea8b"), "ns" : "dbversity.newsql", "min" : { "memsql" : 0.028616901952773333 }, "max" : { "memsql" : 0.9999854390043765 }, "shard" : "rs1" }
{ "_id" : "dbversity.newsql-memsql_0.9999854390043765", "lastmod" : Timestamp(8, 0), "lastmodEpoch" : ObjectId("545b23597532482f2245ea8b"), "ns" : "dbversity.newsql", "min" : { "memsql" : 0.9999854390043765 }, "max" : { "memsql" : { "$maxKey" : 1 } }, "shard" : "rs1" }
{ "_id" : "dbversity.rdbms-oracle_0.5", "lastmod" : Timestamp(6, 0), "lastmodEpoch" : ObjectId("545b23547532482f2245ea89"), "ns" : "dbversity.rdbms", "min" : { "oracle" : 0.5 }, "max" : { "oracle" : 0.9998706732876599 }, "shard" : "rs3" }
mongos>

NOTE
The chunkSize and –chunkSize options, passed at runtime to the mongos, do not affect the chunk size after you have initialized the cluster.

To avoid confusion, always set the chunk size using the above procedure instead of the runtime options.

Modifying the chunk size has several limitations:
———————————————————————–

Automatic splitting only occurs on insert or update.
If you lower the chunk size, it may take time for all chunks to split to the new size.
Splits cannot be undone.
If you increase the chunk size, existing chunks grow only through insertion or updates until they reach the new size.
The allowed range of the chunk size is between 1 and 1024 megabytes, inclusive.

  • Ask Question