MongoDB Performance Issues – Fact or Fiction

I see posts and hear conversations quite frequently about MongoDB performance issues. They are a frequent, and hot, topic on sites like Quora, Hacker News, and Reddit. Many of these “hits” against MongoDB are based on outdated data and older versions of MongoDB.

There was a movie from the late 1980’s called Crocodile Dundee II. There is a scene in the movie where the guy from the Australian Outback, Mick “Crocodile” Dundee, visits a New York City hotel for the first time. Someone shows him that the room has a television. He turns it on and sees an old episode of I Love Lucy. Dundee shuts it off claiming he has already experienced television.

Similarly, many complaints from older versions of MongoDB still linger around. Someone who had a bad experience with an old version will answer a thread somewhere and claim “I used it once, didn’t like it, it’s garbage.” Much like Mick Dundee, they are basing their entire opinion on outdated knowledge.

Let’s take a look at some performance issues that are often raised and where things sit now with the latest version of MongoDB, 3.4.6. I raised some of these aspects in a previous post, but let’s take a deeper dive.

The Jepsen Test & Performance Issues of old

From a “documented issue” standpoint, many performance issues that plague MongoDB in social reviews are covered in a Jepsen test result post from 20 April 2015. This was based on version 2.4.3. Or an even older article from 18 May 2013. Clearly, there were some issues with data scalability and data concurrency in those earlier versions.

In fact, Jepsen has done extensive tests on MongoDB on lost updates and dirty and stale reads. Without getting too deep into the hows and whys of what was happening to the data, there were issues with writes when a primary went down, and read & write consistency. These issues have been addressed as of version 3.4.1.

Product Enhancements

With the new data enhancements, MongoDB version 3.4.1 passed all of the Jepsen tests. Kyle Kingsbury, the creator of Jepsen, offered the following conclusions:

MongoDB has devoted significant resources to improved safety in the past two years, and much of that ground-work is paying off in 3.2 and 3.4.

MongoDB 3.4.1 (and the current development release, 3.5.1) currently pass all MongoDB Jepsen tests….These results hold during general network partitions, and the isolated & clock-skewed primary scenario.

You can read more about his conclusions in his published results.

Beyond data security, customers are finding huge benefits in performance in the more current releases of MongoDB. Improvements to, or the introduction of, technologies such as replication compression, the WiredTiger storage engine, in memory cache, and performance enhancements to sharding and replica sets have been a win for users.

WiredTiger Case Study

A friend who works at Wanderu.com, a MongoDB user, was very generous and forthcoming with some information about their MongoDB experience. When choosing a database option they felt that NoSQL, and MongoDB specifically, fit their business and data model better than a relational model would. They process a very diverse set of data for their bus and train travel application.

They take information from a vast assortment of bus and train vendors which arrive in XML, JSON, PDF, CSV, and other formats. Data is then ingested and transformed so that everything works with price checking and booking calls in vendor specific formats. The data model was determined to be incredibly complex and fragile for implementing in a relational database.

In May 2017, Wanderu migrated to the WiredTiger storage engine in MongoDB 3.4. They took some screenshots of some of their performance graphs. The graphs cover a 10 day period, five before and five after, their migration on 5/5. They were kind enough to share these images with me and approved of their use in this article.

Wanderu Charts
MognoDB Active Reads/Writes
Before WiredTiger, the write load had a very limited max. After migration writes spiked as necessary.
Queued Reads and Writes
Writes stayed fairly constant while queued reads fell dramatically.
MongoDB Index Size
Index size took a dramatic decrease in size as well.
MongoDB Memory Usage
Not surprisingly, Memory Usage dropped too.
MongoDB Page Faults
Page Fault improvements
Replication Lag
If there wasn’t a doubt, replication lag was improved as well.

In the four years since Wanderu launched, it has relied heavily on MongoDB. They store the station and trip information for each local, regional, and national carrier. With the new $graphLookup capability in MongoDB version 3.4, they are looking at the possibility of utilizing that technology for their graphing needs as well.

Further Industry Thoughts

MongoDB is a widely used NoSQL database. It is used by companies large and small, for a variety of reasons. I reached out to a few other known MongoDB users to get some real world feedback and product experiences.

Carfax

CARFAX, for example, has been using MongoDB in production since version 1.8. They load over a billion documents a year and generate over 20,000 reports per second. Jai Hirsch, a Senior Systems Architect at CARFAX, wrote a nice write up about why they decided on MongoDB. They have achieved some tremendous performance benefits from compressed replication.

GHX

GHX switched from MMAPv1 to WiredTiger with the 3.2 release of MongoDB. Jeff Sherard, their Database Engineering Manager, had another very positive experience.

Definitely the switch to WiredTiger in 3.2 was a huge boost. Especially on the compression side – we experience about 50% compression. Document level locking vs. Collection level locking also improved performance for us significantly.

He also experienced benefits with sharding and replica sets as well with an upgrade to 3.4.4.

We recently upgraded to 3.4.4 and are particularly pleased with the improvements in balancing on shards (the parallelism makes balancing really fast). And the initial sync improvements in replica sets [sic] have been really useful too.

Tinkoff Bank

Tinkoff Bank landed on using MongoDB instead of Oracle based on their finding that the performance of Oracle’s CLOBs are not as fast and are not searchable. They are able to process approximately 1,500 requests per second using their three node replica set. These queries put a load of 5-10% on the CPU of the primary node.

Wrap Up

I’m sure that the SQL vs. NoSQL debate will live on. Much the same as Windows vs. Mac, or cats vs. dogs. I hope, however, that based on the information and testimonies provided here we can lay to rest the notion that MongoDB isn’t “enterprise ready.” If we are going to argue the virtues of MongoDB, we should at least be talking about the most current version. As in the scene with Mick Dundee, he comes across looking foolish for basing his entire view of a product based on something he experienced years ago.

There are several MongoDB specific terms in this post. I created a MongoDB Dictionary skill for the Amazon Echo line of products. Check it out and you can say “Alexa, ask MongoDB what is a document?” and get a helpful response.


Follow me on Twitter @kenwalger to get the latest updates on my postings.

Facebooktwitterredditlinkedinmail

Monetary Data Type Storage in MongoDB

One piece of information that is frequently stored in databases is monetary data. Sometimes this poses challenges in data storage as we are left with decisions to be made as to what value to store. One option to store data is to store the data strictly in numeric value. If an item costs $12.99, we could store the monetary value of 12.99 and designate it as USD.

Troubles with Monetary Values

This often can lead to some rounding and data precision issues however when using double values. For example, if a value is 13.4999999999 it might be stored as 13.5000000000. These rounding issues can obviously pose problems over the long run.

Another option might be to store the value as a string which, while maintaining precision, poses some challenges for doing calculations on the data. Another frequent method to store monetary data is to store the value in cents value of the item. Here in the United States, for example, we use dollars that are valued at one-hundred cents. Therefore we could store the value of a $11.99 item as 1199 and then perform conversion calculations to get back to 11.99.

Storing Monetary Values

As mentioned above, we can store data in a variety of ways. In general, however, two basic approaches are taken.

The first approach is to store the value that is displayed to customers, $11.99 in our example as a string and then to also store an approximate value as a float. Something along the lines of:

{
    product_name: "fidget spinner",
    price: { value: "11.99", float_value: 11.99000000000, currency: "USD" }
}

That certainly works, but it still has the potential for rounding errors and there are two different values that must be updated. Wouldn’t it be great if we could simply store our value in the database? Fortunately, there is.

NumberDecimal in MongoDB

One of the features in version 3.4 of MongoDB is support for the NumberDecimal data type. This data type allows for 128-bit decimal based values. It is specifically designed and intended for use for applications needing to store monetary or high precision values. It is an implementation of the BSON decimal type. Since MongoDB stores data in BSON format, it allows us to model monetary data in our database with ease.

Now, for our fidget spinner product, we can model our data using NumberDecimal and take advantage of its features.

{
    product_name: "fidget spinner",
    price: { value: NumberDecimal("11.99"), currency: "USD" }
}

This allows us to not need a scale factor either. Monetary data will be stored on the server in a mathematically useful fashion. This allows for calculations to be made on the server using MongoDB’s aggregation pipeline. By doing calculations on the server we get less network traffic which can ultimately lead to better applications.

Wrap Up

I would highly recommend looking at and using NumberDecimal for your data type when storing monetary data in MongoDB. It is another reason to upgrade to version 3.4. If you haven’t upgraded yet, it might be a good time to do so. Or even better, check out their DBaaS offering Atlas.

There are several MongoDB specific terms in this post. I created a MongoDB Dictionary skill for the Amazon Echo line of products. Check it out and you can say “Alexa, ask MongoDB what is BSON?” and get a helpful response.


Follow me on Twitter @kenwalger to get the latest updates on my postings.

Facebooktwitterredditlinkedinmail