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
insertOne
maps toMongoCollection.insertOne
insertOnePar
a concurrent version ofinsertOne
using Java 8 parallel streaminsertMany
maps toMongoCollection.insertMany
insertManyPar
a concurrent version ofinsertMany
using Java 8 parallel stream with custom batching of the input documentsbulkWriteOrdered
maps toMongoCollection.bulkWrite
withBulkWriteOptions().ordered(true)
bulkWriteOrderedPar
a concurrent version ofbulkWriteOrdered
using Java 8 parallel stream with custom batching of the input documentsbulkWriteUnOrdered
maps toMongoCollection.bulkWrite
withBulkWriteOptions().ordered(false)
bulkWriteUnOrderedPar
a concurrent version ofbulkWriteUnOrdered
using 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.
bulkWriteOrdered
performs (slightly) better thenbulkWriteUnOrdered
. This remains true for the parallel versions.insertMany
is similar to the bulk operations and is better when done in parallel.