Mongodb:database Profiler

Source: Internet
Author: User
Tags mongodb versions

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

Just contact with MongoDB, have used the profile, but not so detailed to read this document, may be the size of their own system is not large enough, if the traffic will inevitably let us look at some performance problems, this time we need to consider the MongoDB Profile, the following begins a detailed analysis: What is the database Profiler.

It is a mongodb provided to analyze the performance of MongoDB, such as what the operation time exceeds the desired threshold, we can in the case of enable profiler from System.profile to see some of the information you want.

Support scenarios for different versions of MongoDB.

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

What 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 status?

By default, profiling is disable, and you can enable it with 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+ {"was": 1, "slowms": 20}

Setprofilinglevel is used to set the profiling level, 0 for the shutdown, 1 for the slow operation of monitoring, as for the slow standard can be set by the second parameter, for example, I think that more than 20ms operation is slow operation, 2 will record all the operation.

Getprofilingstatus is used to view prifiling, was represents the level set, and slowms represents a time threshold.

Of course you can also set the following two parameters when you start MongoDB:

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

Where the profiling information is stored. How to view.

Profiling is the Enable for database settings, 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 care about.

So the qualifier of find can help us a lot and let us quickly navigate to the specified position.

What does every record in system.profile mean?

TS: The time of generation of this record;

Millis: How many MS The operation executes, this time does not include the time to acquire the lock and the network transmission consumption, just the time that the MongoDB process handles it;

Info: A detailed description of the operation:

1) Query

Query begins, indicating that the record is a query statement, followed by four parameter information, Ntoreturn represents the client's query request to return the number of objects, such as the FindOne operation, where the 1,limit operation will show the number of limit, 0 means that there is no limit, how much is returned; query indicates the qualifier used by the specific query, such as {$gte: {x:2}};nscanned Indicates how many documents MongoDB has viewed in order to find documents that meet the query criteria Reslen indicates how many results the query returned bytes;nreturned indicate how many documents the query operation returned.

2) Update

Update, indicating that the record is an update or INSERT statement, followed by five parameter information, fastmode that the operation does not have to wait for the execution to be returned, fastmodinsert that the operation is an insert operation, and do not have to wait for the completion of the return, Can be thought of as asynchronous; Upsert shows that when we call Update, we set Upsert to true, which means that the record is inserted if the record is not found for the specified condition, otherwise the update finds the record; moved indicates that the disk space location is required to update the object. Update was originally in-place update, but because the object is larger, the original space size has not been placed, so have to move, this will reduce the update speed; key updates indicates how many changes on index are affected by this update.

3) Insert

Insert to indicate that the record is an INSERT statement

4) Getmore

Getmore begins by saying that the client is next to find to get more documents, usually a find will only return a portion of the document to the client, and the subsequent document sends a request to MONGODB with the cursor's next method. At this point we can see the Getmore record in system profile.

What's the impact of opening profile?

The time of opening will have a certain effect on the MongoDB speed, although not very serious, profile data is stored in the collection system profile, and this collection is capped collection, So the default scenario for this collection is not very large, so here's a record of some of the most recent operations that are usually saved.

How to optimize query performance.

1) When the size of the nscanned is much larger than the nreturned, the database is looking for the documents we want from a large number of documents, this time to index the conditions of the query.

2) When the value of Reslen is very large, it means that MongoDB returns a lot of data to the client, such as 1M, this time we can give find the second parameter, let the query operation return only those fields that we care about, not blindly return to the client.

How to optimize update performance.

1) Ibid. 1

2) using fast Modify

All of the above is from MongoDB's own offical documentation, interested in reading English documents and doing a hands-on MongoDB profile to 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.