Mongodb – How to remove blockages in MongoDB when multiple write query comes for same collection at same time

mongodb

I want to use MongoDB in a clustered environment with 3 shards and make each shard replicated. MongoDB is a single threaded so when multiple requests hit shard 1 to insert or edit one collection at a same it causes blockages in the architecture.

How can I remove or prevent these blockages?

Best Answer

From the database perspective you can try using, MongoDB 3.0 with the Wired Tiger storage engine to eliminate these waits. MongoDB 3.0 with the Wired Tiger uses Document level blocking and thus brings down the waits considerably.

In case this is not possible, then you cannot do much on the database layer and will either need to live with these waits or will need to handle it from the Application layer.

A tentative approach, which can be used to provide control of the waits from the Application layer can be to queue the respective transactions in the application so that the user does not need to make the changes multiple times.