SlasherZ
SlasherZ

Reputation: 250

Multiple MongoDb databases configuration

I need to create a large number of MongoDb databases, something around 1000+, later it will grow to more than 3000.

They will be hosted on a server with SSD disks and most of the databases will have around 20-30 collections with no more than 500 objects inside. Most of the objects are between 10-50kb in size. So the size of the data inside will be relatevely small.

My question is how should I configure the creation of these mongodb databases, in order to use the disk space in most effective manner. I've read that mongodb allocates empty disk space and that an empty databases can take up to 100MB in size, is there a way to reduce this size?

Upvotes: 1

Views: 173

Answers (1)

Christian P
Christian P

Reputation: 12240

You can set the storage.smallFiles configuration option to true. This will make the initial data and journal files smaller.

From the MongoDB docs:

The storage.smallFiles option reduces the initial size for data files and limits the maximum size to 512 megabytes. storage.smallFiles also reduces the size of each journal file from 1 gigabyte to 128 megabytes. Use storage.sma. lFiles if you have a large number of databases that each holds a small quantity of data.

Depending on your workload, you can also change the record allocation strategy. The exact fit allocation will use less storage space than power of 2 (which is a default allocation strategy for v2.6+). But exact fit allocation is ideal only for collections without update and delete workloads.

Edit

For an empty database With a smallFiles option (let's call it db01), MongoDB will create two files in your dbpath that are 16MB large:

  1. db01.0 - file holding the data
  2. db01.ns - namespace file

As you add documents to your collection MongoDB will create additional files for the data with size: the next one will be 32MB (db01.1), one after that will be 64MB (db01.2) ... up to 512MB. So MongoDB will not preallocate e.g. 1GB for your database if you have only 50MB of data in the collection (if that's what you're worried about).

If you're only worried about the exceeding disk size (on a small SSD), you can also use storage.directoryPerDB. Each database will have it's own directory which you can link to an another disk.

Upvotes: 1

Related Questions