Comparing MongoDB query performance across v2.4, 2.6, 3.0, 3.2 and 3.4

Same hardware, different versions of MongoDB. The newest version is not always the fastest!

We benchmarked queries on a collection of 3M user records across major versions of MongoDB. We were curious to understand where performance improved and regressed from version to version.

About The Data

Collection: 3M Users

dbhash: 5b3992a0f623db11aa9223fe7300a376
download

Benchmark Methodology

  1. import data (mongorestore)
  2. execute set of pre-defined queries sequentially
  3. obtain query execution times from MongoDB profiling (system.profile)
  4. repeat steps 2 and 3 for a total of 10 times

find where array field length $gt 1

Mongodb versions 2.4, 2.6 and 3.0 were able to execute this query in less than half the time as versions 3.2 and 3.4.

{"$where":"this.pets.length > 1","$comment":"q1"}

Thinkpad W550s

v2.4 64bit 0 shards EXT4 Ubuntu 16.04
36,080 ms

Thinkpad W550s

v2.6 64bit 0 shards EXT4 Ubuntu 16.04
36,396 ms

Thinkpad W550s

v3.0 64bit 0 shards EXT4 Ubuntu 16.04
33,329 ms

Thinkpad W550s

v3.2 64bit 0 shards EXT4 Ubuntu 16.04
91,973 ms

Thinkpad W550s

v3.4 64bit 0 shards EXT4 Ubuntu 16.04
92,022 ms

find 'starts with' $regex on string field

All mongodb versions executed this query within a couple hundred milliseconds of each other, performance did neither improve nor regress.

{"firstName":{"$regex":"^bill"},"$comment":"q2"}

Thinkpad W550s

v2.4 64bit 0 shards EXT4 Ubuntu 16.04
1,435 ms

Thinkpad W550s

v2.6 64bit 0 shards EXT4 Ubuntu 16.04
1,570 ms

Thinkpad W550s

v3.0 64bit 0 shards EXT4 Ubuntu 16.04
1,309 ms

Thinkpad W550s

v3.2 64bit 0 shards EXT4 Ubuntu 16.04
1,439 ms

Thinkpad W550s

v3.4 64bit 0 shards EXT4 Ubuntu 16.04
1,476 ms

aggregate $sum

All mongodb versions executed this query within a couple hundred milliseconds of each other, performance did neither improve nor regress.

[{"$match":{"$comment":"q3"}},{"$group":{"_id":"$firstName","incomeSum":{"$sum":"$income"}}}]

Thinkpad W550s

v2.4 64bit 0 shards EXT4 Ubuntu 16.04
2,349 ms

Thinkpad W550s

v2.6 64bit 0 shards EXT4 Ubuntu 16.04
2,406 ms

Thinkpad W550s

v3.0 64bit 0 shards EXT4 Ubuntu 16.04
2,455 ms

Thinkpad W550s

v3.2 64bit 0 shards EXT4 Ubuntu 16.04
2,570 ms

Thinkpad W550s

v3.4 64bit 0 shards EXT4 Ubuntu 16.04
2,542 ms

find object attribute inside array field

Mongodb v2.4 executed this non-indexed query in nearly half the time of all other versions.

{"videoGames.game":"tomb raider","$comment":"q4"}

Thinkpad W550s

v2.4 64bit 0 shards EXT4 Ubuntu 16.04
2,437 ms

Thinkpad W550s

v2.6 64bit 0 shards EXT4 Ubuntu 16.04
4,487 ms

Thinkpad W550s

v3.0 64bit 0 shards EXT4 Ubuntu 16.04
3,953 ms

Thinkpad W550s

v3.2 64bit 0 shards EXT4 Ubuntu 16.04
4,310 ms

Thinkpad W550s

v3.4 64bit 0 shards EXT4 Ubuntu 16.04
3,991 ms

aggregate $avg

v2.4 squeaked out another win (technically) but within a couple hundred milliseconds really isn't saying much.

[{"$match":{"$comment":"q5"}},{"$group":{"_id":"$firstName","incomeAvg":{"$avg":"$income"}}}]

Thinkpad W550s

v2.4 64bit 0 shards EXT4 Ubuntu 16.04
2,259 ms

Thinkpad W550s

v2.6 64bit 0 shards EXT4 Ubuntu 16.04
2,399 ms

Thinkpad W550s

v3.0 64bit 0 shards EXT4 Ubuntu 16.04
2,443 ms

Thinkpad W550s

v3.2 64bit 0 shards EXT4 Ubuntu 16.04
2,537 ms

Thinkpad W550s

v3.4 64bit 0 shards EXT4 Ubuntu 16.04
2,554 ms