Mongodb:database Profiler

Source: Internet
Author: User
Tags mongodb mongodb support

Article Source: Http://www.mongodb.org/display/DOCS/Database+Profiler

Just contact with MongoDB, once used profile, but did not read this document in detail, may be the size of their own system is not big enough, if the volume of visits will inevitably let us look at some performance problems, this time we will consider the MongoDB Profile, the following start the detailed analysis: What is the database Profiler.

It is provided by MongoDB to analyze MongoDB performance, such as what operations are performed longer than expected thresholds, and we can look up some of the information you want from system.profile in the case of enable profiler.

MongoDB support for different versions.

Previous versions of v1.9 can only be used on primary nodes, v1.9+ will also be supported in secondaries

Which level does profiling support?

There are currently three level:0, 1, 2

[C-sharp] view plaincopy 0-off 1-log slow operations (by default, >100ms is considered slow) 2-log a LL operations

If enable profiling and check profiling state?

The default is that profiling is disable, and you can enable it by using the following command line:

[C-sharp] view plaincopy > Db.setprofilinglevel (1,20)//Log slow operations, slow threshold=20ms > Db.ge Tprofilingstatus ()//New Shell helper method as of v1.7+ {"is": 1, "slowms": 20}

Setprofilinglevel is used to set the profiling level, 0 means to shut down, 1 to monitor which slow operation, as for the slow standard can be set by the second parameter, for example, I think more than 20ms operation is slow operation, 2 will record all operations.

Getprofilingstatus is used to view the prifiling, which represents the set level; Slowms represents a time threshold.

Of course, you can also use the following two parameters to set up when starting MongoDB:

[C-sharp] view plaincopy $ MONGO--profile=1--slowms=15

Where profiling information is stored. How to view.

Profiling is set to enable for the database, Profiling Data is recorded in the database System.profile this collection, we can use find to see what's inside, so find uses some query qualifiers to help us see the record we're looking at.

So find qualifier can give us a lot of help, let us quickly navigate to the specified location.

What does every record in system.profile mean?

TS: The generation time of this record;

Millis: The operation of how many MS, this time does not include acquisition of locks and network transmission consumption time, only the MongoDB process to deal with its time;

Info: A detailed description of the operation:

1) Query

At the beginning of query, it means that the record is a query, followed by four parameter information, Ntoreturn represents the number of object that the client's query request returns, such as the FindOne operation, where the 1,limit action shows the number of limit, 0 indicates no limit and how much is returned; query indicates the qualifier used at the time of a specific query, such as {$gte: {x:2}};nscanned says that in order to find documents that meet the query criteria, MongoDB has viewed how many documents Reslen the number of results returned by the query bytes;nreturned indicate how many documents were returned by the query operation.

2) Update

Update, which indicates that the record is an update or INSERT statement followed by five parameter information, fastmode that the operation can be returned without waiting for execution to be completed; Fastmodinsert indicates that the operation is an insert and can be returned without waiting for execution to complete. can be considered asynchronous; Upsert indicates that when we call Update, Upsert is set to true, which means that if you find a record that does not have a specified condition, the update finds the record, and the moved indicates that you need to move the disk space when you update the object. Update is originally in-place update, but because the object becomes larger, the original space size has not been put down, so have to move, this will reduce the update speed; key updates indicates how many changes to the index have been affected by this update.

3) Insert

Inserts, indicating that the record is an INSERT statement

4) Getmore

Getmore, which means that the client is followed by the find to obtain more documents, generally a find will only return a portion of the document to the client, followed by the document with the cursor next method to send the MongoDB request, This is when we can see the Getmore record in system profile.

What's the effect of opening profile?

The opening will have a certain impact on the speed of the MongoDB, although not very serious, profile data is stored in the collection system profile, and this collection is capped collection, So the default case for this collection is not very large, so there is usually a record of some recent operations saved here.

How to optimize query performance.

1 when the size of the nscanned is far greater than the nreturned, the database in a large number of documents to find the documents we want, this time to the query conditions indexed.

2 when the value of Reslen, said MongoDB returned a large number of data to the client, such as 1M, this time we can give find the second parameter, let the query operation only return to our concern of those fields, rather than blindly return to the client.

How to optimize update performance.

1) Ditto 1

2) using fast Modify

The above content all comes from MongoDB own offical document, has the interest oneself may read the English document and the hands-on operation MongoDB profile, see the actual effect.

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.