How can I troubleshoot and resolve high CPU utilization on my DocumentDB instances?
I am experiencing high CPU utilization on my Amazon DocumentDB (with MongoDB compatibility) instances. How can I resolve high CPU utilization?
"I am experiencing high CPU utilization on my Amazon DocumentDB (with MongoDB compatibility) instances. How can I resolve high CPU utilization?Short DescriptionCPU Utilization on your Amazon DocumentDB instances can increase for the following reasons:User-initiated heavy workloadsNon-efficient queriesOverburdening 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:To determine why a DB instance is running slowly, see How Do I Determine Why a System Suddenly Runs Slowly?To identify and terminate long running queries on a DB instance, see How Do I Find and Terminate Long Running or Blocked Queries?To check if a query is progressing, see How Do I Know When a Query Is Making Progress?To determine why a query takes a long time to run, see How Can I See a Query Plan and Optimize a Query?ResolutionSplit workload using replicaSetIf 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 connectionWhen 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 preferredNote: Reads from a read-replica are eventually consistent.Add one or more reader instances to the clusterIf 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 queriesIf the load is spread evenly across all replicas, use profiler to identify slow queries over time.Scale up the instance class of your DB instancesYou 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.Related InformationPerformance and Resource UtilizationBest practices for DocumentDBFollow"