MongoDB – How to Optimize Inserts

mongodb

I have a very write intensive application that I want to optimize. Additionally I don't care about losing data in a crash, as long as there is no corruption in the existing ones.

Is it safe to run with journal disabled in this case? What other options do I have to increase insert performance?

Best Answer

Option 1: Set up a sharded cluster to distribute writes. However a sharded cluster brings complexity in terms of additional components needed (mongos, config servers, multiple replica sets, etc), along with technological overhead you'll need to deal with (balancer, chunk migration, no point-in-time backup/restore, etc).

Option 2: Set default writeConcern to 0, a.k.a. 'fire and forget' mode. Read more here. Basically, your application writes to mongod process (mongod in Primary, if you use a replica set), and receive no acknowledgement back. Two ways to use writeConcern:

  1. Set as default across replica set
  2. Use writeConcern per query

Read more about it here.