Optimizing a MongoDB server instance

In this example study, we are going to optimize a MongoDB single server instance by setting the performance goal of maximizing the throughput of operations toward the database.

Concerning performance tests, we are going to employ YCSB, a popular benchmark created by Yahoo for testing various NoSQL databases.

To extract MongoDB metrics, we are going to spin up a Prometheus instance and we are going to use the MongoDB Prometheus exporter.

Environment setup

Hosts and ports

You can use a single host for both MongoDB and YCSB but, in the following example, we replicate a common pattern in performance engineering by externalizing the load injection tool into a separate instance to avoid performance issues and measurement noise.

Notice: in the following, the assumption is to be working with Linux hosts.

Prometheus and exporters

To correctly extract MongoDB metrics we can leverage a solution like Prometheus, paired with the MongoDB Prometheus exporter. To do so we would need to:

  1. Install the MongoDB Prometheus exporter on mongo.mycompany.com

  2. Install and configure Prometheus on ycsb.mycompany.com

Install the MongoDB Prometheus exporter

You can check how to install the exporter here. On Ubuntu you can use the system package manager:

By default, the exporter will expose MongoDB metrics on port 9100

Install and configure Prometheus

You can check how to configure Prometheus here; by default, it will run on port 9090.

The following YAML fileprometheus.yaml is an example of the Prometheus configuration that you can use.

System

Since we are interested in tuning MongoDB by acting on its configuration parameters and by observing its throughput measured using YCSB, we need two components:

  • A mongo component which represents the MongoDB instance all the configuration parameters and maps directly to mongo.mycompany.com

  • A ycsb component which represents YCSB, in particular, it "houses" the metrics of the performance test, which can be used as parts of the goal of a study. This component maps directly to ucsb.mycompany.com

Here’s the definition of our system (system.yaml):

Here’s the definition of our mongo component (mongo.yaml):

Here’s the definition of our ycsb component (ycsb.yaml):

We can create the system by running:

We can then create the components by running:

Workflow

As described in the MongoDB optimization pack page, a workflow for optimizing MongoDB can be structured in three main steps:

  1. Configure MongoDB with the configuration parameters decided by Akamas

  2. Test the performance of the application

  3. Prepare test results

Notice: here we have omitted the Cleanup step because it is not necessary for the context of this study.

Configure MongoDB

We can define a workflow task that uses the FileConfigurator operator to interpolate Akamas parameters into a MongoDB configuration script:

Here’s an example of a templated configuration script for MongoDB:

We can add a workflow task that actually executes the MongoDB configuration script produced by the FileConfigurator:

In each task, we leveraged the reference to the "mongo" component to fetch from its properties all the authentication info to ssh into the right machine e let the FileConfigurator and Executor do their work

Test the performance of the application

We can define a workflow task that uses the Executor operator to launch the YCSB benchmark against MongoDB:

Here’s an example of a launch script for YCSB:

Prepare test results

We can define a workflow task that launches a script that parses the YCSB results into a CSV file (Akamas will process the CSV file and then extract performance test metrics):

Complete workflow

By putting together all the tasks defined above we come up with the following workflow definition (workflow.yaml):

We can create the workflow by running:

Telemetry

Prometheus

Since we are employing Prometheus to extract MongoDB metrics, we can leverage the Prometheus provider to start ingesting data-points into Akamas. To use the Prometheus provider we need to define a telemetry-instance (prom.yaml):

Notice: the fact that the instance definition contains the specification of Prometheus queries to map to Akamas metrics is temporary. In the next release, these queries will be embedded in Akamas.

By default, $DURATION$ will be replaced with 30s. You can override it to your needs by setting a duration property under prometheus within your mongo component

We can now create the telemetry instance and attach it to our system by running:

CSV

Beyond MongoDB metrics, it is important to ingest into Akamas metrics related to the performance tests run with YCSB, in particular the throughput of operations. To achieve this we can leverage the CSV Provider which parses a CSV file to extract relevant metrics. The CSV file we are going to parse with the help of the provider is the one produced in the last task of the workflow of the study.

To start using the provider, we need to define a telemetry instance (csv.yaml):

We can create the telemetry instance and attach it to our system by running:

Study

Our goal for optimizing MongoDB is to maximize its throughput, measured using a performance test executed with YCSB.

Goal

Here’s the definition of the goal of our study, to maximize the throughput:

Windowing

It is important that the throughput of our MongoDB instance should be considered valid only when it is stable, for this reason, we can use the stability windowing policy. This policy identifies a period of time with at least 100 samples with a standard deviation lower than 200 when the application throughput is maximum.

Parameters to optimize

We are going to optimize every MongoDB parameter:

Steps

We are going to add to our study two steps:

  • A baseline step, in which we set a cache size of 1GB and use the default values for all the other MongoDB parameters

  • An optimize step, in which we perform 100 experiments to generate the best configuration for MongoDB

Here’s what these steps look like:

Complete study

Here’s the study definition (study.yaml) for optimizing MongoDB:

You can create the study by running:

You can then start it by running:

Last updated

Was this helpful?