Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Tutorials
    • All tutorials
    • Deploying the Apache Kafka® web interface
    • Migrating a database from a third-party Apache Kafka® cluster to Managed Service for Apache Kafka®
    • Moving data between Managed Service for Apache Kafka® clusters using Data Transfer
    • Delivering data from Managed Service for MySQL® to Managed Service for Apache Kafka® using Data Transfer
    • Delivering data from Managed Service for MySQL® to Managed Service for Apache Kafka® using Debezium
    • Delivering data from Managed Service for PostgreSQL to Managed Service for Apache Kafka® using Data Transfer
    • Delivering data from Managed Service for PostgreSQL to Managed Service for Apache Kafka® using Debezium
    • Delivering data from Managed Service for YDB to Managed Service for Apache Kafka® using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for ClickHouse® using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for Greenplum® using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for MongoDB using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for MySQL® using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for OpenSearch using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for PostgreSQL using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Managed Service for YDB using Data Transfer
    • Delivering data from Managed Service for Apache Kafka® to Data Streams using Data Transfer
    • Delivering data from Data Streams to Managed Service for YDB using Data Transfer
    • Delivering data from Data Streams to Managed Service for Apache Kafka® using Data Transfer
    • YDB change data capture and delivery to YDS
    • Configuring Kafka Connect to work with a Managed Service for Apache Kafka® cluster
    • Automating Query tasks with Managed Service for Apache Airflow™
    • Sending requests to the Yandex Cloud API via the Yandex Cloud Python SDK
    • Configuring an SMTP server to send e-mail notifications
    • Adding data to a ClickHouse® DB
    • Migrating data to Managed Service for ClickHouse® using Data Transfer
    • Delivering data from Managed Service for MySQL® to Managed Service for ClickHouse® using Data Transfer
    • Asynchronously replicating data from PostgreSQL to ClickHouse®
    • Exchanging data between Managed Service for ClickHouse® and Yandex Data Processing
    • Configuring Managed Service for ClickHouse® for Graphite
    • Fetching data from Managed Service for Apache Kafka® to Managed Service for ClickHouse®
    • Fetching data from Managed Service for Apache Kafka® to ksqlDB
    • Fetching data from RabbitMQ to Managed Service for ClickHouse®
    • Saving a Data Streams data stream in Managed Service for ClickHouse®
    • Asynchronous replication of data from Yandex Metrica to ClickHouse® using Data Transfer
    • Using hybrid storage in Managed Service for ClickHouse®
    • Sharding Managed Service for ClickHouse® tables
    • Data resharding in a Managed Service for ClickHouse® cluster
    • Loading data from Yandex Direct to a data mart enabled by Managed Service for ClickHouse® using Cloud Functions, Object Storage, and Data Transfer
    • Loading data from Object Storage to Managed Service for ClickHouse® using Data Transfer
    • Migrating data with change of storage from Managed Service for OpenSearch to Managed Service for ClickHouse® using Data Transfer
    • Loading data from Managed Service for YDB to Managed Service for ClickHouse® using Data Transfer
    • Migrating databases from Google BigQuery to Managed Service for ClickHouse®
    • Configuring Cloud DNS to access a Managed Service for ClickHouse® cluster from other cloud networks
    • Migrating a Yandex Data Processing HDFS cluster to a different availability zone
    • Importing data from Managed Service for MySQL® to Yandex Data Processing using Sqoop
    • Importing data from Managed Service for PostgreSQL to Yandex Data Processing using Sqoop
    • Mounting Object Storage buckets to the file system of Yandex Data Processing hosts
    • Working with Apache Kafka® topics using Yandex Data Processing
    • Automating operations with Yandex Data Processing using Managed Service for Apache Airflow™
    • Shared use of Yandex Data Processing tables through Metastore
    • Transferring metadata between Yandex Data Processing clusters using Metastore
    • Importing data from Object Storage, processing and exporting to Managed Service for ClickHouse®
    • Migrating to Managed Service for Elasticsearch using snapshots
    • Migrating collections from a third-party MongoDB cluster to Managed Service for MongoDB
    • Migrating data to Managed Service for MongoDB
    • Migrating Managed Service for MongoDB cluster from 4.4 to 6.0
    • Sharding MongoDB collections
    • MongoDB performance analysis and tuning
    • Migrating a database from a third-party MySQL® cluster to a Managed Service for MySQL® cluster
    • Managed Service for MySQL® performance analysis and tuning
    • Syncing data from a third-party MySQL® cluster to Managed Service for MySQL® using Data Transfer
    • Migrating a database from Managed Service for MySQL® to a third-party MySQL® cluster
    • Migrating a database from Managed Service for MySQL® to Object Storage using Data Transfer
    • Migrating data from Object Storage to Managed Service for MySQL® using Data Transfer
    • Delivering data from Managed Service for MySQL® to Managed Service for Apache Kafka® using Data Transfer
    • Delivering data from Managed Service for MySQL® to Managed Service for Apache Kafka® using Debezium
    • Migrating a database from Managed Service for MySQL® to Managed Service for YDB using Data Transfer
    • MySQL® change data capture and delivery to YDS
    • Migrating data from Managed Service for MySQL® to Managed Service for PostgreSQL using Data Transfer
    • Migrating data from AWS RDS for PostgreSQL to Managed Service for PostgreSQL using Data Transfer
    • Migrating data from Managed Service for MySQL® to Managed Service for Greenplum® using Data Transfer
    • Configuring an index policy in Managed Service for OpenSearch
    • Migrating data from Elasticsearch to Managed Service for OpenSearch
    • Migrating data from a third-party OpenSearch cluster to Managed Service for OpenSearch using Data Transfer
    • Loading data from Managed Service for OpenSearch to Object Storage using Data Transfer
    • Migrating data from Managed Service for OpenSearch to Managed Service for YDB using Data Transfer
    • Copying data from Managed Service for OpenSearch to Managed Service for Greenplum® using Yandex Data Transfer
    • Migrating data from Managed Service for PostgreSQL to Managed Service for OpenSearch using Data Transfer
    • Authenticating a Managed Service for OpenSearch cluster in OpenSearch Dashboards using Keycloak
    • Using the yandex-lemmer plugin in Managed Service for OpenSearch
    • Creating a PostgreSQL cluster for 1C:Enterprise
    • Searching for the Managed Service for PostgreSQL cluster performance issues
    • Managed Service for PostgreSQL performance analysis and tuning
    • Logical replication PostgreSQL
    • Migrating a database from a third-party PostgreSQL cluster to Managed Service for PostgreSQL
    • Migrating a database from Managed Service for PostgreSQL
    • Delivering data from Managed Service for PostgreSQL to Managed Service for Apache Kafka® using Data Transfer
    • Delivering data from Managed Service for PostgreSQL to Managed Service for Apache Kafka® using Debezium
    • Delivering data from Managed Service for PostgreSQL to Managed Service for YDB using Data Transfer
    • Migrating a database from Managed Service for PostgreSQL to Object Storage
    • Migrating data from Object Storage to Managed Service for PostgreSQL using Data Transfer
    • PostgreSQL change data capture and delivery to YDS
    • Migrating data from Managed Service for PostgreSQL to Managed Service for MySQL® using Data Transfer
    • Migrating data from Managed Service for PostgreSQL to Managed Service for OpenSearch using Data Transfer
    • Troubleshooting string sorting issues in PostgreSQL after upgrading glibc
    • Migrating a database from Greenplum® to ClickHouse®
    • Migrating a database from Greenplum® to PostgreSQL
    • Exporting Greenplum® data to a cold storage in Object Storage
    • Loading data from Object Storage to Managed Service for Greenplum® using Data Transfer
    • Copying data from Managed Service for OpenSearch to Managed Service for Greenplum® using Yandex Data Transfer
    • Creating an external table from a Object Storage bucket table using a configuration file
    • Migrating a database from a third-party Valkey™ cluster to Yandex Managed Service for Valkey™
    • Using a Yandex Managed Service for Valkey™ cluster as a PHP session storage
    • Loading data from Object Storage to Managed Service for YDB using Data Transfer
    • Loading data from Managed Service for YDB to Object Storage using Data Transfer
    • Processing Audit Trails events
    • Processing Cloud Logging logs
    • Processing CDC Debezium streams
    • Analyzing data with Jupyter
    • Processing files with usage details in Yandex Cloud Billing
    • Entering data into storage systems
    • Smart log processing
    • Transferring data within microservice architectures
    • Migrating data to Object Storage using Data Transfer
    • Migrating data from a third-party Greenplum® or PostgreSQL cluster to Managed Service for Greenplum® using Data Transfer
    • Migrating Managed Service for MongoDB clusters
    • Migrating MySQL® clusters
    • Migrating to a third-party MySQL® cluster
    • Migrating PostgreSQL clusters
    • Creating a schema registry to deliver data in Debezium CDC format from Apache Kafka®

In this article:

  • Getting started
  • Diagnosing resource shortages
  • Troubleshooting resource shortage issues
  • Diagnosing inefficient query execution
  • Troubleshooting issues with inefficient queries
  • Diagnosing locks
  • Troubleshooting locking issues
  • Diagnosing insufficient disk space
  • Troubleshooting disk space issues
  1. Building a data platform
  2. MongoDB performance analysis and tuning

Performance analysis and tuning of MongoDB

Written by
Yandex Cloud
Updated at October 28, 2024
  • Getting started
  • Diagnosing resource shortages
  • Troubleshooting resource shortage issues
  • Diagnosing inefficient query execution
  • Troubleshooting issues with inefficient queries
  • Diagnosing locks
  • Troubleshooting locking issues
  • Diagnosing insufficient disk space
  • Troubleshooting disk space issues

In this tutorial, you will learn how to:

  • Use performance diagnostic tools and monitoring tools.
  • Troubleshoot identified issues.

Managed Service for MongoDB cluster performance drops most often due to one of the following:

  • High CPU and disk I/O utilization.
  • Inefficient query execution in MongoDB.
  • Locks.
  • Insufficient disk space.

Here are some tips for diagnosing and fixing these issues.

Getting startedGetting started

  1. Install the mongostat and mongotop utilities on an external host with network access to your MongoDB host (see Pre-configuring a connection to a MongoDB cluster) to receive MongoDB performance data.
  2. Determine which databases need to be checked for issues.
  3. Create a MongoDB user with the mdbMonitor role for these databases. You need to do this in order to use mongostat and mongotop.

Diagnosing resource shortagesDiagnosing resource shortages

If some of the CPU and disk I/O resources "hit a plateau", that is, the curve of the graph that was previously steadily ascending has leveled off, it's probably due to a resource shortage, which led to reduced performance. This usually happens when the resource usage reaches its limit.

In most cases, high CPU utilization and high Disk IO are due to suboptimal indexes or a large load on the hosts.

Start diagnostics by identifying the load pattern and problematic collections. Use the built-in MongoDB monitoring tools. Next, analyze the performance of specific queries using logs or profiler data.

Pay attention to queries:

  • Not using indexes (planSummary: COLLSCAN). Such queries may affect both I/O consumption (more reads from the disk) and CPU consumption (data is compressed by default and decompression is required for it). If the required index is present, but the database does not use it, you can force its usage with hint.
  • With large docsExamined values (number of scanned documents). This may mean that the currently running indexes are inefficient or additional ones are required.

As soon as performance drops, you can diagnose the problem in real time using a list of currently running queries:

Queries from all users
Queries from the current user

To run these queries, users needs the mdbMonitor role.

  • Long queries, such as those taking more than one second to execute:

    db.currentOp({"active": true, "secs_running": {"$gt": 1}})
    
  • Queries to create indexes:

    db.currentOp({ $or: [{ op: "command", "query.createIndexes": { $exists: true } }, { op: "none", ns: /\.system\.indexes\b/ }] })
    
  • Long queries, such as those taking more than one second to execute:

    db.currentOp({"$ownOps": true, "active": true, "secs_running": {"$gt": 1}})
    
  • Queries to create indexes:

    db.currentOp({ "$ownOps": true, $or: [{ op: "command", "query.createIndexes": { $exists: true } }, { op: "none", ns: /\.system\.indexes\b/ }] })
    

See also the examples in the MongoDB documentation.

Troubleshooting resource shortage issuesTroubleshooting resource shortage issues

Try optimizing the identified queries. If the load is still high or there is nothing to optimize, the only option is to upgrade the host class.

Diagnosing inefficient query executionDiagnosing inefficient query execution

To identify problematic queries in MongoDB:

  • Review the logs. Pay special attention to:

    • For read queries, the responseLength field (written as reslen in the logs).
    • For write queries, the number of affected documents.
      In the cluster logs, they are displayed in the nModified, keysInserted, and keysDeleted fields. On the cluster monitoring page, analyze the Documents affected on primary, Documents affected on secondaries, and Documents affected per host graphs.
  • Review the profiler data. Output long-running queries (adjustable with the slowOpThreshold DBMS setting).

Troubleshooting issues with inefficient queriesTroubleshooting issues with inefficient queries

Each individual query can be analyzed in terms of the query plan. Learn more about this in the MongoDB documentation:

  • Query analysis guide.
  • Reference for the db.collection.explain function.

Analyze the graphs on the cluster monitoring page:

  • Index size on primary, top 5 indexes.
  • Scan and order per host.
  • Scanned / returned.

To more quickly narrow down the search scope, use indexes.

Warning

Each new index slows down writes. Too many indexes may negatively affect write performance.

To optimize read requests, use projection. In many cases, you need to return only a few fields rather than the entire document.

If you can neither optimize the queries you found nor go without them, upgrade the host class.

Diagnosing locksDiagnosing locks

Poor query performance can be caused by locks.

MongoDB does not provide detailed information on locks. There are only indirect ways to find out what is locking a specific query:

  • Pay attention to large or growing db.serverStatus().metrics.operation.writeConflicts values: they may indicate high write contention on some documents.

  • Examine large or growing values using the Write conflicts per hosts graph on the cluster monitoring page.

  • As soon as performance drops, carefully review the list of currently running queries:

    Queries from all users
    Queries from the current user

    To run these queries, the user needs the mdbMonitor role.

    • Find queries that hold exclusive locks, such as:

      db.currentOp({'$or': [{'locks.Global': 'W'}, {'locks.Database': 'W'}, {'locks.Collection': 'W'} ]}).inprog
      
    • Find queries waiting for locks (the timeAcquiringMicros field shows the waiting time):

      db.currentOp({'waitingForLock': true}).inprog
      db.currentOp({'waitingForLock': true, 'secs_running' : { '$gt' : 1 }}).inprog
      
    • Find queries that hold exclusive locks, such as:

      db.currentOp({"$ownOps": true, '$or': [{'locks.Global': 'W'}, {'locks.Database': 'W'}, {'locks.Collection': 'W'} ]}).inprog
      
    • Find queries waiting for locks (the timeAcquiringMicros field shows the waiting time):

      db.currentOp({"$ownOps": true, 'waitingForLock': true}).inprog
      db.currentOp({"$ownOps": true, 'waitingForLock': true, 'secs_running' : { '$gt' : 1 }}).inprog
      
  • Pay attention to the following in the logs and profiler:

    • Queries that had waited a long time to get locks will have large timeAcquiringMicros values.
    • Queries that had competed for the same documents will have large writeConflicts values.

Learn more about which locks are used by standard client and administrative queries in the official MongoDB documentation.

Troubleshooting locking issuesTroubleshooting locking issues

Detected locks indicate unoptimized queries. Try optimizing problematic queries.

Diagnosing insufficient disk spaceDiagnosing insufficient disk space

If a cluster shows poor performance combined with a small amount of free disk space, this is probably because one or more hosts in the cluster switched to "read-only".

The amount of used disk space is displayed on the Disk space usage per host, top 5 hosts graphs on the cluster monitoring page.

To monitor storage usage on cluster hosts, configure an alert.

Troubleshooting disk space issuesTroubleshooting disk space issues

For recommendations on troubleshooting these issues, see Maintaining a cluster in operable condition.

Was the article helpful?

Previous
Sharding MongoDB collections
Next
Migrating a database from a third-party MySQL® cluster to a Managed Service for MySQL® cluster
Yandex project
© 2025 Yandex.Cloud LLC