command testdb.test command: find { find: "test", filter: { $and: [ { u_id: { $ne: null } }, { u_id: { $ne: "" } } ] }, sort: { r_at: -1 }, projection: { b_qp: 0, r_cp: 0 }, skip: 15990, limit: 10 } planSummary: IXSCAN { r_at: -1 } keysExamined:25125 docsExamined:25125 cursorExhausted:1 numYields:196 nreturned:10 reslen:1017 locks:{ Global: { acquireCount: { r: 394 } }, Database: { acquireCount: { r: 197 } }, Collection: { acquireCount: { r: 197 } } } protocol:op_query 122ms
如上的日志怎么解读在调教优化MongoDB的过程显得尤为重要,这里做下文档解释。
MongoDB日志文件官方文档在:Database Profiler Output
section of the MongoDB documentation to get a detailed explanation of the query profile information like read and write operations, cursor operations, and database commands that MongoDB writes to the log. To answer your question
fsync: - Forces the mongod process to flush all pending writes from the storage layer to disk.
keyUpdates: - The number of index keys the update changed in the operation. Changing an index key carries a small performance cost because the database must remove the old key and inserts a new key into the B-tree index.
numYield: - The number of times the operation yielded to allow other operations to complete. Typically, operations yield when they need access to data that MongoDB has not yet fully read into memory. This allows other operations that have data in memory to complete while MongoDB reads in data for the yielding operation.
responseLength (reslen): - 返回的长度,以字节为单位,如果太长可能会引发问题。
keysExamined: - 3.2.0版之前的 nscanned 此数字记录了MongoDB查询以找到结果的操作次数。如果此值比nreturned值高很多,证明数据库寻找了很多元素才找到目标内容,这种情况下一般需要建立一个索引提高效率。
nMatched: -查询到的结果数量。 If the update operation results in no change to the document, e.g. $set expression updates the value to the current value, nMatched can be greater than nModified.
nModified: - The number of existing documents updated. If the update/replacement operation results in no change to the document, such as setting the value of the field to its current value, nModified can be less than nMatched.
locks
里面是一些锁机制的参数。
locks(micros): - 记录了不同种类锁执行的次数。
R - global read lock
W - global write lock
r - database-specific read lock
w - database-specific write lock
timeLockedMicros: - The time in microseconds the operation held a specific lock. For operations that require more than one lock, like those that lock the local database to update the oplog, this value may be longer than the total length of the operation (i.e. millis.)
numYields: 记录了MongoDB被打断了多少次,一般来说是因为等待数据从数据库读入内存,这个个过程中让出进程让结果在内存中的查询先返回。