On this page本页内容
As you develop and operate applications with MongoDB, you may need to analyze the performance of the application and its database. 在使用MongoDB开发和操作应用程序时,您可能需要分析应用程序及其数据库的性能。When you encounter degraded performance, it is often a function of database access strategies, hardware availability, and the number of open database connections.当您遇到性能下降时,这通常是数据库访问策略、硬件可用性和打开的数据库连接数的函数。
Some users may experience performance limitations as a result of inadequate or inappropriate indexing strategies, or as a consequence of poor schema design patterns. 由于索引策略不充分或不适当,或者由于模式设计模式不佳,一些用户可能会遇到性能限制。Locking Performance discusses how these can impact MongoDB's internal locking.锁定性能讨论了这些因素如何影响MongoDB的内部锁定。
Performance issues may indicate that the database is operating at capacity and that it is time to add additional capacity to the database. 性能问题可能表明数据库正在满负荷运行,是时候向数据库添加额外容量了。In particular, the application's working set should fit in the available physical memory.特别是,应用程序的工作集应该适合可用的物理内存。
In some cases performance issues may be temporary and related to abnormal traffic load. 在某些情况下,性能问题可能是暂时的,并与异常流量负载有关。As discussed in Number of Connections, scaling can help relax excessive traffic.正如在连接数中所讨论的,缩放可以帮助缓解过多的流量。
Database Profiling数据库分析 can help you to understand what operations are causing degradation.可以帮助您了解哪些操作导致降级。
MongoDB uses a locking system to ensure data set consistency. MongoDB使用锁定系统来确保数据集的一致性。If certain operations are long-running or a queue forms, performance will degrade as requests and operations wait for the lock.如果某些操作长时间运行或形成队列,则性能将随着请求和操作等待锁定而降低。
Lock-related slowdowns can be intermittent. 与锁相关的减速可能是间歇性的。To see if the lock has been affecting your performance, refer to the locks section and the globalLock section of the 要查看锁是否影响了性能,请参阅serverStatus输出的锁部分和全局锁部分。serverStatus
output.
Dividing 将locks.<type>.timeAcquiringMicros
by locks.<type>.acquireWaitCount
can give an approximate average wait time for a particular lock mode.locks.<type>.timeAcquiringMicros
除以locks.<type>.acquireWaitCount
可以给出特定锁定模式的近似平均等待时间。
locks.<type>.deadlockCount
provide the number of times the lock acquisitions encountered deadlocks.提供锁获取遇到死锁的次数。
If 如果globalLock.currentQueue.total
is consistently high, then there is a chance that a large number of requests are waiting for a lock. globalLock.currentQueue.total
始终较高,则有可能有大量请求等待锁定。This indicates a possible concurrency issue that may be affecting performance.这表明可能存在影响性能的并发问题。
If 如果globalLock.totalTime
is high relative to uptime
, the database has existed in a lock state for a significant amount of time.globalLock.totalTime
相对于正常运行时间较高uptime
,则数据库已处于锁定状态很长时间。
Long queries can result from ineffective use of indexes; non-optimal schema design; poor query structure; system architecture issues; or insufficient RAM resulting in disk reads.长查询可能是由于索引的无效使用造成的;非最优方案设计;查询结构差;系统架构问题;或RAM不足导致磁盘读取。
In some cases, the number of connections between the applications and the database can overwhelm the ability of the server to handle requests. 在某些情况下,应用程序和数据库之间的连接数量可能会超过服务器处理请求的能力。The following fields in the serverStatus
document can provide insight:serverStatus
文档中的以下字段可以提供详细信息:
connections
is a container for the following two fields:是以下两个字段的容器:
connections.current
connections.available
If there are numerous concurrent application requests, the database may have trouble keeping up with demand. 如果有大量并发应用程序请求,数据库可能无法跟上需求。If this is the case, then you will need to increase the capacity of your deployment.如果是这种情况,则需要增加部署的容量。
For write-heavy applications, deploy sharding and add one or more shards to a sharded cluster to distribute load among 对于写重的应用程序,部署分片并将一个或多个分片添加到分片集群,以在mongod
instances.mongod
实例之间分配负载。
Spikes in the number of connections can also be the result of application or driver errors. 连接数的峰值也可能是应用程序或驱动程序错误的结果。All of the officially supported MongoDB drivers implement connection pooling, which allows clients to use and reuse connections more efficiently. 所有官方支持的MongoDB驱动程序都实现了连接池,这允许客户端更有效地使用和重用连接。An extremely high number of connections, particularly without corresponding workload, is often indicative of a driver or other configuration error.极高数量的连接,特别是没有相应的工作负载的连接,通常表示驱动程序或其他配置错误。
Unless constrained by system-wide limits, the maximum number of incoming connections supported by MongoDB is configured with the 除非受到系统范围的限制,否则MongoDB支持的最大传入连接数是使用maxIncomingConnections
setting. maxIncomingConnections
设置配置的。On Unix-based systems, system-wide limits can be modified using the 在基于Unix的系统上,可以使用ulimit
command, or by editing your system's /etc/sysctl
file. ulimit
命令或通过编辑系统的/etc/sysctl
文件来修改系统范围的限制。See UNIX 有关详细信息,请参阅UNIX ulimit
Settings for more information.ulimit
设置。
The Database Profiler collects detailed information about operations run against a mongod instance. 数据库探查器集合有关针对mongod
实例运行的操作的详细信息。The profiler's output can help to identify inefficient queries and operations.探查器的输出可以帮助识别效率低下的查询和操作。
You can enable and configure profiling for individual databases or for all databases on a 您可以为单个数据库或mongod
instance. mongod
实例上的所有数据库启用和配置评测。Profiler settings affect only a single 探查器设置仅影响单个mongod
instance and will not propagate across a replica set or sharded cluster.mongod
实例,不会跨副本集或分片集群传播。
See Database Profiler for information on enabling and configuring the profiler.有关启用和配置探查器的信息,请参阅数据库探查器。
The following profiling levels are available:以下分析级别可用:
Level | |
---|---|
0 | |
1 | slowms .slowms 值花费更长时间的操作集合数据。
|
2 |
Profiling can impact performance and shares settings with the system log. 分析可能会影响性能,并与系统日志共享设置。Carefully consider any performance and security implications before configuring and enabling the profiler on a production deployment.在生产部署中配置和启用探查器之前,请仔细考虑任何性能和安全影响。
See Profiler Overhead for more information on potential performance degradation.有关潜在性能下降的更多信息,请参阅探查器开销。
When 当logLevel
is set to 0
, MongoDB records slowoperations to the diagnostic log at a rate determined by slowOpSampleRate
.logLevel
设置为0
时,MongoDB将以slowOpSampleRate
确定的速率将慢操作记录到诊断日志中。
At higher 在更高的logLevel
settings, all operations appear in the diagnostic log regardless of their latency with the following exception: the logging of slow oplog entry messages by the secondaries. logLevel
设置下,所有操作都会显示在诊断日志中,而不管它们的延迟如何,但以下例外情况除外:辅助设备记录慢速oplog条目消息。The secondaries log only the slow oplog entries; increasing the 二级仅记录慢速oplog条目;增加logLevel
does not log all oplog entries.logLevel
不会记录所有oplog条目。
Starting in MongoDB 4.2, the profiler entries and the diagnostic log messages (i.e. mongod/mongos log messages) for read/write operations include:从MongoDB 4.2开始,用于读/写操作的探查器条目和诊断日志消息(即mongod
/mongos
日志消息)包括:
queryHash
to help identify slow queries with the same query shape.queryHash
有助于识别具有相同查询形状的慢速查询。planCacheKey
To facilitate analysis of the MongoDB server behavior by MongoDB Inc. engineers, 为了便于MongoDB股份有限公司工程师分析MongoDB服务器行为,mongod
and mongos
processes include a Full Time Diagnostic Data Collection (FTDC) mechanism. mongod
和mongos
进程包括一个全职诊断数据集合(FTDC)机制。FTDC data files are compressed, are not human-readable, and inherit the same file access permissions as the MongoDB data files. Only users with access to FTDC data files can transmit the FTDC data. FTDC数据文件被压缩,不可读,并继承与MongoDB数据文件相同的文件访问权限。只有能够访问FTDC数据文件的用户才能传输FTDC数据。MongoDB Inc. engineers cannot access FTDC data independent of system owners or operators. MongoDB股份有限公司的工程师无法独立于系统所有者或运算符访问FTDC数据。MongoDB processes run with FTDC on by default. 默认情况下,MongoDB进程在FTDC打开的情况下运行。For more information on MongoDB Support options, visit Getting Started With MongoDB Support.有关MongoDB支持选项的更多信息,请访问开始使用MongoDB。
FTDC data files are compressed and not human-readable. FTDC数据文件是压缩的,不可读。MongoDB Inc. engineers cannot access FTDC data without explicit permission and assistance from system owners or operators.没有系统所有者或运算符的明确许可和协助,MongoDB股份有限公司工程师无法访问FTDC数据。
FTDC data never contains any of the following information:FTDC数据从不包含以下任何信息:
FTDC data contains certain host machine information such as hostnames, operating system information, and the options or settings used to start the FTDC数据包含某些主机信息,如主机名、操作系统信息以及用于启动mongod
or mongos
. mongod
或mongos
的选项或设置。This information may be considered protected or confidential by some organizations or regulatory bodies, but is not typically considered to be Personally Identifiable Information (PII). 某些组织或监管机构可能认为该信息受到保护或保密,但通常不认为是个人身份信息(PII)。For clusters where these fields were configured with protected, confidential, or PII data, please notify MongoDB Inc. engineers before sending the FTDC data so appropriate measures can be taken.对于这些字段配置了受保护、机密或PII数据的集群,请在发送FTDC数据之前通知MongoDB股份有限公司的工程师,以便采取适当的措施。
FTDC periodically collects statistics produced by the following commands:FTDC定期集合由以下命令生成的统计信息:
serverStatus
replSetGetStatus
(mongod
only)collStats
for the local.oplog.rs
collection (mongod
only)connPoolStats
(mongos
only)Depending on the host operating system, the diagnostic data may include one or more of the following utilization statistics:根据主机操作系统,诊断数据可以包括以下利用率统计中的一个或多个:
Starting in MongoDB 4.4, if the 从MongoDB 4.4开始,如果mongod
process runs in a container, FTDC will report utilization statistics from the perspective of the container instead of the host operating system. mongod
进程在容器中运行,FTDC将从容器而不是主机操作系统的角度报告利用率统计数据。For example, if a the 例如,如果mongod
runs in a container that is configured with RAM restrictions, FTDC will calculate memory utilization against the container's RAM limit, as opposed to the host operating system's total available RAM.mongod
在配置有RAM限制的容器中运行,FTDC将根据容器的RAM限制计算内存利用率,而不是主机操作系统的总可用RAM。
FTDC collects statistics produced by the following commands on file rotation or startup:FTDC集合以下命令在文件旋转或启动时生成的统计信息:
mongod
processes store FTDC data files in a 进程将FTDC数据文件存储在实例diagnostic.data
directory under the instances storage.dbPath
. storage.dbPath
下的diagnostic.data
目录中。All diagnostic data files are stored under this directory. 所有诊断数据文件都存储在此目录下。For example, given a 例如,给定dbPath
of /data/db
, the diagnostic data directory would be /data/db/diagnostic.data
./data/db
的dbPath
,诊断数据目录将是/data/db/diagnostic.data
。
mongos
processes store FTDC data files in a diagnostic directory relative to the 进程将FTDC数据文件存储在相对于systemLog.path
log path setting. systemLog.path
日志路径设置的诊断目录中。MongoDB truncates the logpath's file extension and concatenates MongoDB截断日志路径的文件扩展名,并将diagnostic.data
to the remaining name. diagnostic.data
连接到剩余名称。For example, given a 例如,给定path
setting of /var/log/mongodb/mongos.log
, the diagnostic data directory would be /var/log/mongodb/mongos.diagnostic.data
./var/log/mongodb/mongos.log
的path
设置,诊断数据目录将为/var/log/mongodb/mongos.diagnostic.data
。
FTDC runs with the following defaults:FTDC使用以下默认值运行:
diagnostic.data
folder size.diagnostic.data
文件夹大小为200MB。These defaults are designed to provide useful data to MongoDB Inc. engineers with minimal impact on performance or storage size. 这些默认值旨在为MongoDB股份有限公司的工程师提供有用的数据,对性能或存储大小的影响最小。These values only require modifications if requested by MongoDB Inc. engineers for specific diagnostic purposes.仅当MongoDB股份有限公司工程师出于特定诊断目的要求时,才需要修改这些值。
You can view the FTDC source code on the MongoDB Github Repository. 您可以在MongoDB Github存储库中查看FTDC源代码。The ftdc_system_stats_*.ccp
files specifically define any system-specific diagnostic data captured.ftdc_system_stats_*.ccp
文件专门定义捕获的任何系统特定诊断数据。
To disable FTDC, start up the 要禁用FTDC,请启动mongod
or mongos
with the diagnosticDataCollectionEnabled: false
option specified to the setParameter
setting in your configuration file:mongod
或mongos
,并为配置文件中的setParameter
设置指定diagnosticDataCollectionEnabled: false
选项:
setParameter: diagnosticDataCollectionEnabled: false
Disabling FTDC may increase the time or resources required when analyzing or debugging issues with support from MongoDB Inc. engineers.在MongoDB股份有限公司工程师的支持下分析或调试问题时,禁用FTDC可能会增加所需的时间或资源。