MongoDB Database Profiling

Source: Internet
Author: User
Tags mongodb profiler mongo shell

MongoDB Database Profiling



MongoDB Profiler is a system that captures database execution activity, which can help identify slow queries and operations.

Profiling level



The available capture levels have the following meanings:


level Set

0 disable

1 enabled, only slow operation is logged

2 Enable, log all operations

View Profiling level


> Db.getprofilinglevel ()

Enable Profiler


> Db.setprofilinglevel (1)

The complete command is:

Db.setprofilinglevel (LEVEL,SLOWMS)


When level is 1, the default value for slow operation is 100ms, if you specify a slow operation of 500ms:

> Db.setprofilinglevel (1,500)

Attention:

By default, Mongod records all slow queries (defined by SHOWOPTHRESHOLDMS with a default value of 100ms) to the MongoDB log file.

Enable profiling only at critical times and try not to enable it in a production environment.

Enables profiling based on a standalone Mongod instance. This setting will not spread to other instances through a replica set or a shard cluster.

View Profiler Results



Use System.profile to record, while System.profile is a capped collection. In the System.profile collection of your database, call the MONGO shell command show profile, or query the System.profile collection to see the output of the profiler, such as:

Db.system.profile.find ({millis: {$gt: 1000}})

can be output, query time is more than 1 seconds of slow query.

Profiler Detailed information Content



ts-when the command is executed.

Millis time-the command execution takes time, in milliseconds.

info-This command for more information.

Query-indicates that this is a query operation.

ntoreturn-the number of records returned by this query client. For example, the FindOne () command executes with a ntoreturn of 1. Ntoreturn is n when there is a limit (n) condition.


query-specific query conditions (such as x>3).

nscanned-the number of records scanned for this query.

reslen-returns the size of the result set.

nreturned-The result set actually returned by this query.

Update-indicates that this is an update operation.

Fastmod-indicates a fast modify operation. See Updates. These operations is normally quite fast.

Fastmodinsert–indicates A fast modify operation that performed an upsert.


Upsert-indicates that the Upsert parameter for update is true. The function of this parameter is to insert a record with the update condition if the record for the update does not exist.

Moved-Indicates whether the update has moved the data on the hard disk, if the new record is shorter than the original record, usually does not move the current record, if the new record is longer than the original record, you may move the record to another location, This will result in an update of the relevant index. More disk operations, plus index updates, can make such operations slower.


Insert-This is an insert insertion operation.

Getmore-This is a getmore operation, getmore usually occurs when the result set is larger than the query, the first query returns partial results, and subsequent results are obtained through Getmore.

Performance optimization

Although we do not have profiler enabled, in a production environment, we can still see a slow operation greater than 100ms in the log file.

Tail-f/data/var/log/mongodb/mongod.log
Mon may 02:57:22.670 [conn756] Query Mytest.pro query: {$query: {cutepath:/^122-133-1456 (-\d+) *$/, Avail.status: {$ Lt:5}, $or: [{_id: {$lt: 3310}}, {_id: {$gt: 8520, $lt: 8530}}, {_id: {$gt: 9720, $lt: 9730}}}, $orderby : {avail.status:1, Avgrate:-1}} ntoreturn:200 ntoskip:0 nscanned:18764 scanandorder:1 keyupdates:0 numyields:10 Lock S (micros) r:217999 nreturned:200 reslen:563505 116ms


If nscanned (the number of records scanned) is much larger than nreturned (the number of records that return results), then we need to consider Gazzo to optimize record positioning.


Reslen if it is too large, then the result set that we return is too large, please check if the second parameter of the Find function writes only the property name you need.


The recommendation for creating an index is to try not to add an index if it is rarely read, because the more indexes, the slower the write operation. If you read a large amount, then it is better to create an index.

See:

http://docs.mongodb.org/manual/administration/analyzing-mongodb-performance/#database-profiling

Http://docs.mongodb.org/master/MongoDB-crud-guide.pdf


This article is from the SQL Server deep dives blog, so be sure to keep this source http://ultrasql.blog.51cto.com/9591438/1654989

MongoDB Database Profiling

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.