About eric

Author Archive | eric

About eric

Here are my most recent posts

Tuning MongoDB Performance with MMS

At MongoLab we manage thousands of MongoDB clusters and regularly help customers optimize system performance. Some of the best tools available for gaining insight into our MongoDB deployments are the monitoring features of MongoDB Management Service (MMS). MMS allows us to quickly determine the health of a MongoDB system and identify the root cause of performance issues. This post covers our general approach to using MMS and MongoDB log files and provides techniques to help you optimize your own MongoDB deployment, whether you’re in the cloud or on your own hardware.

First, we will define the key metrics that we use to guide any performance investigation. Then we will go through the various combinations of metric values, discuss what they mean, and explore how to address the problems they indicate.

Continue Reading →

{ "comments": 3 }

[“Thinking”, “About”, “Arrays”, “In”, “MongoDB”]

Greetings adventurers!

The growing popularity of MongoDB means more and more people are thinking about data in ways divergent from traditional relational models. For this reason alone, it’s exciting to experiment with new ways of modelling data. However, with additional flexibility comes the need to properly analyze the performance impact of data model decisions.

Embedding arrays in documents is a great example of this. MongoDB’s versatile array operators ($push/$pull, $addToSet, $elemMatch, etc.) offer the ability to manage data sets within documents. However, one must be careful. Data models that call for very large arrays, or arrays with high rates of modification, can often lead to performance problems.

Continue Reading →

{ "comments": 23 }

How to use MongoDB on RedHat OpenShift with MongoLab

Hey RedHat fans – we’ve got your MongoDB hosting needs covered!

In today’s post we’ll be presenting a quick-start guide on how to connect OpenShift, the free RedHat auto-scaling Platform-as-a-Service (PaaS), with our popular MongoDB Database-as-a-Service (DBaaS), MongoLab.

For demonstration purposes, we’ll be using a Node.js application that we’ve written (available for download here). All it takes to connect your OpenShift application is five easy steps!

Continue Reading →

{ "comments": 6 }

Node.js and MongoLab on Windows Azure

(This tutorial was originally published on the Windows Azure documentation portal in January 2013)

Greetings, adventurers! Welcome to MongoDB-as-a-Service. Are you looking to create a Node.js Application on Windows Azure with MongoDB using the MongoLab Azure Store add-on?

In this tutorial you will:

  1. Provision the database – The Windows Azure Store MongoLab add-on will provide you with a MongoDB database hosted in the Windows Azure cloud and managed by MongoLab‘s cloud database platform.
  2. Create the app – It’ll be a simple Node.js app for maintaining a list of tasks.
  3. Deploy the app – By tying a few configuration hooks together, we’ll make pushing our code a breeze.
  4. Manage the database – Finally, we’ll show you MongoLab’s web-based database management portal where you can search, visualize, and modify data with ease.

At any time throughout this tutorial, feel free to kick off an email to support@mongolab.com if you have any questions. To complete this tutorial, you need a Windows Azure account that has the Windows Azure Web Sites feature enabled. You can create a free trial account and enable preview features in just a couple of minutes. For details, see the Create a Windows Azure account and enable preview features tutorial.

In addition, ensure that you have the following installed:
Continue Reading →

Dex 0.5: Weighted Index Recommendations for MongoDB

Greetings, adventurers!

I am happy to announce the latest version of Dex, MongoLab’s Index Bot. With version 0.5, we’re declaring Dex halfway-there in terms of major features. The most important and convenient improvements in this version are Weighted Index Recommendations and support for MongoDB 2.2 log files.

If you haven’t given Dex a try yet, check out the README and sudo pip install dex to get started. Even if you are already a Dex user, I highly recommend you revisit the readme, as Dex’s output has changed.

Now when you run Dex, Dex compiles statistics for its recommendations, and provides those in its output. In contrast to prior versions, this gives a weight to each suggested index, clearly identifying the worst offenders.

Here’s a rundown of major changes:

  • Weighted Recommendations – For each recommendation, Dex tallies the number of affected queries, the total time consumed by those queries, and the average time for a single query. Note that Dex keeps subtotal statistics for each unique query pattern that prompted a given recommendation. Subtotals are available in –verbose/-v mode only.
  • Output changes – We’ve modified Dex’s output for the purposes of readability and convenience, in the following ways:
    • By default (i.e., not in –watch/-w mode), Dex no longer provides runtime output. Dex reads the entire profile collection or log file and then outputs one set of full results.
    • In –watch/-w mode, Dex still provides runtime output, periodically printing all recommendations with up-to-date statistics.
    • The shell command suggestion is removed from default output in favor of concise, weighted index recommendations. The shell command is still available in –verbose/-v output, but is no longer included by default.
  • Support for MongoDB 2.2 log files – While Dex has supported MongoDB 2.2 in –profile/-p mode, updates to Dex’s log file regexes now support recent updates to the MongoDB log file line format.

For more information about Dex, check out Introducing Dex. As always, good luck out there!

Sincerely,
Eric@MongoLab

{ "comments": 2 }

Remote Dex: Index Analysis Using the Profile Collection

(also posted to the 10gen blog: here)

Greetings Adventurers!

I’m excited to report that Dex (github) is now equipped with his first planned upgrade. For those of you who haven’t met him, Dex is an open-source python tool that suggests indexes for your MongoDB database. The initial release of Dex supported logfile-based analysis only. Now, Dex can be run remotely by leveraging MongoDB’s built-in database profiler. This new feature is invoked with the -p or --profile option. When you run Dex with -p, it connects to the specified MongoDB database and analyzes the queries already logged to your system.profile collection.

As the diagram below shows, this is particularly good news for MongoLab’s shared plan customers and anyone who does not have direct terminal access to their database machine.

In case you missed my introduction of Dex at the San Francisco MongoDB User Group Meetup, I’ll be presenting Dex at the Silicon Valley MongoDB Users Group on July 17 at 10gen’s offices in Palo Alto!

Here’s a quick set of steps to get you started.

  1. If you haven’t already, get Dex:
    sudo pip install dex
  2. Or, if you already have Dex:
    sudo pip install dex --upgrade
  3. Log into your database through the mongo shell and run db.setProfilingLevel(1). If your MongoDB is hosted with us at MongoLab, you can also enable profiling through our UI.
  4. Let your app run for a while. With profiling enabled, MongoDB deposits documents into system.profile. By default, each of these documents represents a database operation that took more than 100ms to complete. For apps that perform specific operation at specific times, you will need to profile during those times. Once you feel that your profile collection is populated with a representative set of data, you’re ready to run Dex!
  5. Run Dex with --profile or -p (instead of -f):
    dex <mongodb-uri> -p

    Where <mongodb-uri> is your database connection string (ex: mongodb://me:mypassword@myserver.mongolab.com:27227/mydb)

    Note: If you use a Sandbox plan on MongoLab (or do not have an admin URI for other reasons) you must provide a -n/–namespace filter to narrow your request, or your Dex attempt will fail for authentication reasons. (ex: -n "mydb.*")

    > dex mongodb://me:mypassword@myserver.mongolab.com:27227/mydb -p -n "mydb.*"

  6. Dex outputs index recommendations and corresponding creation syntax.  Because Dex relies on heuristics that don’t take your data into account, you’ll want to validate and sanity check Dex’s suggestions before implementing.
  7. Run db.setProfilingLevel(0) to disable profiling when you’re done. Profiling requires a small bit of overhead and is entirely diagnostic, so you don’t need to leave it running. If you like, you can also drop the system.profile collection afterwards.
  8. Enjoy!

As always: if you have any questions, bug reports, or feature requests, please email us at support@mongolab.com.

Until next time, good luck out there!

Sincerely,
Eric@MongoLab

(updates 2012-07-16: fixed missing URI; 2012-07-17: added 10gen cross-post URL)

{ "comments": 2 }

Introducing Dex: the Index Bot

(update 2012-07-19: A new remote feature detailed here.)
(update 2012-10-09: Version 0.5 detailed here.)

Greetings adventurers! MongoLab is pleased to introduce Dex! We hope he assists you on your quests.


Dex is a MongoDB performance tuning tool, open-sourced under the MIT license, that compares logged queries to available indexes in the queried collection(s) and generates index suggestions based on a simple rule of thumb. To use Dex, you provide a path to your MongoDB log file and a connection URI for your database. Dex is also registered with PyPi, so you can install it easily with pip.

Quick Start

pip install dex

THEN

dex -f mongodb.log mongodb://localhost

Dex provides runtime output to STDERR as it finds recommendations:

{
"index": "{'simpleIndexedField': 1, 'simpleUnindexedFieldThree': 1}",
"namespace": "dex_test.test_collection",
"shellCommand": "db.test_collection.ensureIndex(
  {'simpleIndexedField': 1, 'simpleUnindexedFieldThree': 1},
  {'background': true})"
}

As well as summary statistics:

Total lines read: 7
Understood query lines: 7
Unique recommendations: 5
Lines impacted by recommendations: 5

Just copy and paste each shellCommand value into your MongoDB shell to create the suggested indexes.

Dex also provides the complete analysis on STDOUT when it’s done, so you will see this information repeated before Dex exits. The output to STDOUT is an entirely JSON version of the above, so Dex can be part of an automated toolchain.

For more information check out the README.md and tour the source code at https://github.com/mongolab/dex. Or if you’re feeling extra adventurous, fiddle with the source yourself!

git clone https://github.com/mongolab/dex.git

The motivation behind Dex

MongoLab manages tens of thousands of MongoDB databases, heightening our sensitivity to slow queries and their impact on CPU.  What started as a set of Continue Reading →

{ "comments": 16 }

Cardinal $ins: MongoDB Query Performance over Ranges

Greetings adventurers! If you’ve been travelling through MongoDB indexing territory for any amount of time, you may have heard or derived the following maxim: If your queries contain a sort/orderby clause, add the sorted field to the end of the index servicing the query.

In many cases when querying for documents containing equivalent values, the above mantra is very helpful (by equivalency, I mean querying for a specific value in a field, such as {“name” : “Charlie”}). But what about the following:

Query

db.drivers.find({"country": {"$in": ["A", "G"]}).sort({"carsOwned": 1})

Index

{"country": 1, "carsOwned": 1}


This pairing is not as performant as one might expect, even though the index follows the maxim. That’s because there’s a very specific trap that this conventional wisdom may lead you into.

Below, we’ll walk through why that is, and by the end of this blog you’ll have a new rule of thumb to guide you when indexing. Continue Reading →

{ "comments": 27 }