OPTIONS
翻译或纠错本页面

数据库 Profiler输出

数据库 Profiler 记录了关于读写操作,游标操作和数据库命令相关的数据信息。关于配置数据库profile和设置记录profile数据的阈值这部分,请参见 Analyze Performance of Database Operations

数据库profiler把数据写入 system.profile 集合中,该集合是一个 capped collection 。可以用普通的MongoDB查询语句查询 system.profile 集合得到profiler的输出。

注解

因为数据库profiler将数据写入数据库的 system.profile 集合,所以profiler将会记录一些活跃的写,即使是那些只读数据库。

Example system.profile Document

The documents in the system.profile collection have the following form. This example document reflects an update operation:

{
    "ts" : ISODate("2012-12-10T19:31:28.977Z"),
    "op" : "update",
    "ns" : "social.users",
    "query" : {
        "name" : "j.r."
    },
    "updateobj" : {
        "$set" : {
            "likes" : [
                "basketball",
                "trekking"
            ]
        }
    },
    "nscanned" : 8,
    "scanAndOrder" : true,
    "moved" : true,
    "nmoved" : 1,
    "nupdated" : 1,
    "keyUpdates" : 0,
    "numYield" : 0,
    "lockStats" : {
        "timeLockedMicros" : {
            "r" : NumberLong(0),
            "w" : NumberLong(258)
        },
        "timeAcquiringMicros" : {
            "r" : NumberLong(0),
            "w" : NumberLong(7)
        }
    },
    "millis" : 0,
    "client" : "127.0.0.1",
    "user" : ""
}

输出参考

对任何单个操作来说,数据库profiler创建的文档包含下列字段的子集。依靠操作类型在这些文档中进行精确的字段筛选。

system.profile.ts

时间戳操作

system.profile.op

操作类型。可能的值有:

  • insert
  • query
  • update
  • remove
  • getmore
  • command
system.profile.ns

The namespace the operation targets. Namespaces in MongoDB take the form of the database, followed by a dot (.), followed by the name of the collection.

system.profile.query

The query document used.

system.profile.command

命令操作。

system.profile.updateobj

在进行 update 操作时传递的 <update> 文档。

system.profile.cursorid

游标的ID通过 getmore 操作访问。

system.profile.ntoreturn

在 2.2 版更改: 在2.0版本中,MongoDB的 querycommand 操作中包含这个字段。在2.2中,这些信息仍然存在,并在 getmore 操作中包含这个字段。

指定操作返回的文档数量。比如, profile 命令返回一个文档(一个结果文档),所以 ntoreturn 的值为1. limit(5) 命令会返回五个文档,所以 ntoreturn 的值为5.

如果 ntoreturn 的值为0,表示命令没有指定返回文档数,比如一个简单的 find() 命令就没有指定限制值。

system.profile.ntoskip

2.2 新版功能.

The number of documents the skip() method specified to skip.

system.profile.nscanned

为了执行该操作,MongoDB在 index 中浏览的文档数。

一般来说,如果 nscanned 值高于 nreturned 的值,说明数据库为了找到目标文档扫描了很多文档。这时可以考虑创建索引来提高效率。

system.profile.scanAndOrder

scanAndOrder is a boolean that is true when a query cannot use the order of documents in the index for returning sorted results: MongoDB must sort the documents after it receives the documents from a cursor.

如果 scanAndOrder ,MongoDB可以利用建有索引的文档顺序返回已排序的结果。

system.profile.moved

当一个更新操作将一个或多个文档移至磁盘上新的地方时,这个字段值为 。如果更新操作没有产生移动作用,那么该字段不会出现。产生移动行为的操作会比本地更新花费更多的时间,通常还会发生文档增长。

system.profile.nmoved

2.2 新版功能.

该操作在磁盘上移动的文档数。该字段只会在操作产生移动时出现。其实该字段隐含为0,但是为非0时才会出现。

system.profile.nupdated

2.2 新版功能.

操作更新的文档数。

system.profile.keyUpdates

2.2 新版功能.

在操作里更新的改变 index 的数量。改变一个索引值会消耗一点性能,因为数据库必须移掉老的值并插入新的值到B-tree索引中。

system.profile.numYield

2.2 新版功能.

该操作为了使其他操作完成而放弃的次数。通常来说,当他们需要访问还没有完全读入内存中的数据时,操作将放弃。这使得在MongoDB为了放弃操作进行数据读取的同时,还有数据在内存中的其他操作可以完成。更多的相关信息请参见 the FAQ on when operations yield

system.profile.lockStats

2.2 新版功能.

该操作获得并持有锁花费的时间。该字段记录了下面锁类型的数据:

  • R - global read lock
  • W - global write lock
  • r - database-specific read lock
  • w - database-specific write lock
system.profile.lockStats.timeLockedMicros

该操作获取一个级锁花费的时间。对于请求多个锁的操作,比如对 local 数据库锁来更新 oplog ,该值比该操作的总长要长(即 millis

system.profile.lockStats.timeAcquiringMicros

该操作等待获取一个级锁花费的时间。

system.profile.nreturned

该操作返回的文档数。

system.profile.responseLength

该操作结果文档的大小。一个大的 responseLength 会影响性能。为了限制一个查询操作返回的文档大小,您可以使用下列操作:

注解

当MongoDB将查询的慢日志信息写入日志时, responseLength 值在 reslen 字段里。

system.profile.millis

The time in milliseconds from the perspective of the mongod from the beginning of the operation to the end of the operation.

system.profile.client

该操作引起的客户端连接的IP地址或域名。

对于像 db.eval() 这样的一些操作,客户端用 0.0.0.0:0 代替实际的客户端地址。

system.profile.user

执行该操作的认证用户。