How to speed up MongoDB Inserts/sec? How to speed up MongoDB Inserts/sec? mongodb mongodb

How to speed up MongoDB Inserts/sec?


Writes to MongoDB currently aquire a global write lock, although collection level locking is hopefully coming soon. By using more threads you're likely introducing more concurrency problems as the threads block eachother while they wait for the lock to be released.

Indexes will also slow you down, to get the best insert performance it's ideal to add them after you've loaded your data, however this isn't always possible, for example if you're using a unique index.

To really maximise write performance, your best bet is sharding. This'll give you a much better concurrency and higher disk I/O capacity as you distribute writes across several machines.


2 threads currently do more per sec than 16 threads on a 16 core dual processor machine.

MongoDB inserts cannot be done concurrently. Every insert needs to acquire a write lock. Not sure if that is a global or a per-collection lock, but in your case that would not make a difference.

So making this program multi-threaded does not make much sense as soon as Mongo becomes the bottleneck.

Do I need to use sharding?

You cannot shard a capped collection.


I've noticed that building the index after inserting helps.