The Java MongoDB driver (here at ver: 3.2.0) exposes several flavours by which documents can be inserted. mongoinserts.Inserts exercises some of them while recording TPS information.
The data used here is the primer-dataset (copy checked in) . It contains 25359 restaurant listings
in JSON format
insertOnemaps toMongoCollection.insertOneinsertOnePara concurrent version ofinsertOneusing Java 8 parallel streaminsertManymaps toMongoCollection.insertManyinsertManyPara concurrent version ofinsertManyusing Java 8 parallel stream with custom batching of the input documentsbulkWriteOrderedmaps toMongoCollection.bulkWritewithBulkWriteOptions().ordered(true)bulkWriteOrderedPara concurrent version ofbulkWriteOrderedusing Java 8 parallel stream with custom batching of the input documentsbulkWriteUnOrderedmaps toMongoCollection.bulkWritewithBulkWriteOptions().ordered(false)bulkWriteUnOrderedPara concurrent version ofbulkWriteUnOrderedusing Java 8 parallel stream with custom batching of the input documents
Local instance of MongoDB, default concerns. Each flavour is run multiple times, before each run the collection is dropped. The duration of each run is recorded and the last N runs are averaged to produce a TPS number.
The absolute values are not very useful as they depend on hardware to a very large degree (if you are really curious I get between 10k and 70k doc/sec depending on the flavour).
Consequently all results here are normalized by the slowest result which is insertOne:
insertOne 1.0
insertOnePar 3.4
insertMany 2.6
insertManyPar 6.2
bulkWriteUnordered 2.5
bulkWriteUnorderedPar 5.7
bulkWriteOrdered 2.7
bulkWriteOrderedPar 6.0
- In every case the concurrent version produces better throughput then the serial.
bulkWriteOrderedperforms (slightly) better thenbulkWriteUnOrdered. This remains true for the parallel versions.insertManyis similar to the bulk operations and is better when done in parallel.