The performance of the BSON library in reading and writing complex documents is critical to ensuring that the driver has the best possible performance. A series of performance/benchmark JUnit tests have been created to compare the driver to the MongoDB Inc. supported (legacy) driver. These benchmarks are provided as part of the mongodb-async-performance GitHub project.

The chart below shows the relative performance of the legacy driver's BSON library vs. the Asynchronous drivers BSON library when using the unbuffered I/O library.

The Asynchronous driver provides two stream classes for writing BSON documents. The first (BufferedBsonStream) buffers all of the data being written for the document so that the sizes of various documents and fields can be written at the start of each. The second (BsonStream) uses a visitor across the BSON AST (abstract syntax tree) to compute the sizes needed for the size prefixes in the BSON document specification.

In previous releases the driver used the unbuffered stream as it offered superior performance. With the 2.0.0 release we have managed to remove the buffer management over head and as can be seen below the buffered stream now out performs the unbuffered streams in all tests. The driver has now switched to using the buffered streams. The driver continues to perform better than the MongoDB Inc. version.

Figure 1 - Relative Performance of the MongoDB Inc. (legacy) and Asynchronous drivers BSON libraries when reading and writing documents of various sizes.

Test Environment

All tests were performed on computer with a Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz and 16GB of memory running Fedora 20. JDK 1.7.0_55 was used. The tests operate completely within the JVM and repeat each read/write 1,000,000 times.

Test Results

The raw performance data is provided in the analysis spreadsheet.