How can I troubleshoot and resolve high CPU utilization on my DocumentDB instances?

Last updated: 2020-06-17

I am experiencing high CPU utilization on my Amazon DocumentDB (with MongoDB compatibility) instances. How can I resolve high CPU utilization?

Short Description

CPU Utilization on your Amazon DocumentDB instances can increase for the following reasons:

  • User-initiated heavy workloads
  • Non-efficient queries
  • Overburdening the writer or specific DB instance in the cluster, instead of balancing the load within the cluster.

Use the following resources to troubleshoot CPU performance issues:


Split workload using replicaSet

If you have a DocumentDB cluster with multiple DB instances, check if the writer CPU is high and if the readers are sitting idle. This means the writer is overloaded.

To resolve this, split the workload using replicaSet or use multiple connection pools to route read queries to the reader DB instances.

Specify the readPreference for your connection

When you connect as a replica set, you can specify the readPreference for the connection. If you specify a read preference of secondaryPreferred, the client routes read queries to your replicas, and write queries to your primary DB instance. The following example shows the connection string in Python:

## Create a MongoDB client, open a connection to Amazon DocumentDB as a
##   replica set and specify the read preference as secondary preferred

Note: Reads from a read-replica are eventually consistent.

Add one or more reader instances to the cluster

If you have a DocumentDB cluster with a single DB instance (writer only), add one or multiple reader DB instances to the cluster. Then, use readPreference=secondaryPreferred to handle the load efficiently.

Use Profiler to identify slow queries

If the load is spread evenly across all replicas, use profiler to identify slow queries over time.

Scale up the instance class of your DB instances

You can also scale up the instance class of the DB instances in the DocumentDB cluster to handle the workload.

Note: Scaling up the instance class increases the cost. Refer to DocumentDB pricing for more information.

Did this article help you?

Anything we could improve?

Need more help?