profile

On this page本页内容

Definition定义

profile

Changed in version 5.0.在版本5.0中更改

For a mongod instance, the command enables, disables, or configures the Database Profiler. 对于mongod实例,该命令启用、禁用或配置数据库探查器The profiler captures and records data on the performance of write operations, cursors, and database commands on a running mongod instance. 探查器捕获并记录有关正在运行的mongod实例上写操作、游标和数据库命令的性能的数据。If the profiler is disabled, the command configures how slow operations are logged to the diagnostic log.如果禁用探查器,则该命令将配置将操作记录到诊断日志的速度。

On mongod, if the database profiler level is 1 or 2 (i.e. the database profiler is enabled), the slowms, sampleRate, and filter affect the behavior of both the profiler and the diagnostic log.mongod上,如果数据库探查器级别12(即启用了数据库探查器),则slowmssampleRatefilter会影响探查器和诊断日志的行为。

If the database profiler level is 0 (i.e. database profiler is disabled), the slowms, sampleRate, and filter affect only the diagnostic log.如果数据库探查器级别0(即禁用数据库探查器),则slowmssampleRate筛选器仅影响诊断日志。

Starting in MongoDB 4.0, for a mongos instance, the command only configures how operations get written to the diagnostic log. 从MongoDB 4.0开始,对于mongos实例,该命令只配置如何将操作写入诊断日志。You cannot enable the Database Profiler on a mongos instance because mongos does not have any collections that the profiler can write to.您不能在mongos实例上启用数据库探查器,因为mongos没有探查器可以写入的任何集合。

Starting in MongoDB 5.0 (also available starting in 4.4.2, 4.2.12, and 4.0.22), changes made to the database profiler level, slowms, sampleRate, or filter using the profile command or db.setProfilingLevel() wrapper method are recorded in the log file.从MongoDB 5.0开始(也可从4.4.2、4.2.12和4.0.22开始),使用profile命令或dbsetProfileLevel()包装器方法对数据库探查器levelslowmssampleRatefilter所做的更改将记录在日志文件中。

On mongos, you can set profile level to:mongos上,您可以将配置文件级别设置为:

  • 0 to set the slowms, sampleRate, and filter for the diagnostic log;0设置诊断日志的slowmssampleRatefilter
  • -1 to read the current settings.读取当前设置。

The profiler is off by default.默认情况下,探查器处于关闭状态。

Important重要

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.有关潜在性能降级的更多信息,请参阅探查器开销

The profile command has the following syntax:profile命令具有以下语法:

{
  profile: <level>,
  slowms: <threshold>,
  sampleRate: <rate>,
  filter: <filter expression>
}
Field字段Type类型Description描述
profileint

Configures the profiler level. 配置探查器级别。The following profiler levels are available:以下探查器级别可用:

LevelDescription描述
0The profiler is off and does not collect any data. 探查器已关闭,未集合任何数据。This is the default profiler level.这是默认的探查器级别。
1The profiler collects data for operations that take longer than the value of slowms.探查器为耗时超过slowms值的操作集合数据。
2The profiler collects data for all operations.探查器集合所有操作的数据。

Since profiling is not available on mongos, the profile command cannot be used to set the profiling level to a value other than 0 on a mongos instance.由于mongos上不提供评测,因此在mongos实例上不能使用profile命令将评测级别设置为0以外的值。

slowmsint

Optional. 可选。Default: 100

The slow operation time threshold, in milliseconds. 慢速操作时间阈值,以毫秒为单位。Operations that run for longer than this threshold are considered slow.运行时间超过此阈值的操作被认为是缓慢的。

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 logLevel does not log all oplog entries.辅助服务器仅记录慢速oplog条目;增加logLevel不会记录所有oplog条目。

Note注意

This argument affects the same setting as the configuration option slowOpThresholdMs.此参数影响与配置选项slowOpThresholdMs相同的设置。

sampleRatedouble

Optional. 可选。Default: 1.0默认值:1.0

The fraction of slow operations that should be profiled or logged.应分析或记录的慢速操作的百分比。
sampleRate accepts values between 0 and 1, inclusive.sampleRate接受介于0和1之间的值(包括0和1)。
Note注意

This argument affects the same setting as the configuration option slowOpSampleRate and does not affect the slow oplog entry log messages on secondaries (available starting in MongoDB 4.2).此参数影响与配置选项slowOpSampleRate相同的设置,不会影响secondary上的慢oplog条目日志消息(从MongoDB 4.2开始提供)。

filterobject

Optional.可选。

A filter expression that controls which operations are profiled and logged.控制分析和记录哪些操作的筛选器表达式。

The filter expression takes the following form:filter表达式采用以下形式:

{ <field1>: <expression1>, ... }

The <field> can be any field in the profiler output. <field>可以是探查器输出中的任何字段。The <expression> is a query condition expression.<expression>是一个查询条件表达式

Note注意

This argument affects the same setting as the configuration option filter. 此参数影响与配置选项filter相同的设置。When filter is set, the slowms and sampleRate options are not used for profiling and slow-query log lines.设置filter后,slowmssampleRate选项不用于评测和慢速查询日志行。

New in version 4.4.2.在版本4.4.2中新增

The db.getProfilingStatus() and db.setProfilingLevel() shell methods provide wrappers around the profile command.db.getProfilingStatus()db.setProfilingLevel()shell方法profile命令提供包装器。

Behavior行为

The profile command obtains a write lock on the affected database while enabling or disabling the profiler. profile命令在启用或禁用探查器时获取受影响数据库的写入锁定。This is typically a short operation. 这通常是一个短操作。The lock blocks other operations until the profile command has completed.锁将阻止其他操作,直到profile命令完成。

Starting in MongoDB 4.4.2, when connected to a sharded cluster through mongos, you can run the profile command against any database. 从MongoDB 4.4.2开始,当通过mongos连接到分片集群时,可以对任何数据库运行profile命令。In previous versions of MongoDB, when connected through mongos, you can only run the profile command against the admin database.在MongoDB的早期版本中,当通过mongos连接时,您只能对admin数据库运行profile命令。

Tip提示
See also: 参阅:
←  pingserverStatus →