Summary
The previous article introduced the MapReduce aggregation operation. This article will continue to learn, DB has, collection and document also have, basically enough, but as the project on-line, found more and more business data, query efficiency is more and more slow, then need to analyze slow query records. How do I turn on slow query logging? That's what this article is about.
Related articles
Getting started with [MongoDB]
[MongoDB] additions and deletions change
[Mongodb]count,gourp,distinct
[Mongodb]mapreduce
[MongoDB] Index
Profiling
First add the test data, add 100w bar.
Insert time is longer, you can view the log through the server
Time is long, insert so many, can explain the problem on the line
First, you need to analyze whether you need to index, the previous version can be viewed through the Expalin function, but the current version, the result of this function is the following situation. The indexfilterset can only see that no index is used, and other information will not help us.
Below this is a one-line yard friend's picture can compare the original text: http://www.cnblogs.com/huangxincheng/archive/2012/02/29/2372699.html
However, there is another way, through the profiling, can be started on the server to add this parameter, –profile= level.
It can also be configured in real time via the client Db.setprofilinglevel (level) command. The current profile level can be obtained through the db.getprofilinglevel () command.
Level is available in three different levels
0– not open
--Record slow command (default = >100ms)
--Record all orders
When the parameter is 1, the default slow command is greater than 100ms, and of course it can be set
1, 120);
Mongodb profile record is directly in the system DB, record location system.profile, we just query this collection record can get to our profile record.
Executes the query and then executes the profile
> Db.users.find ({"Name": "Wolfy" +66666"_id": ObjectId ("5752486fc74b6bdc94876d95"), "name": "wolfy66666" , "Age": 13471 }> Db.system.profile.find ()
Analysis results
{ "OP": "Query", "NS": "Test.system.profile", "Query": { "Find": "System.profile", "Filter": { } }, "Keysexamined": 0, "Docsexamined": 0, "Cursorexhausted":true, "Keyupdates": 0, "Writeconflicts": 0, "Numyield": 0, "Locks": { "Global": { "Acquirecount": { "R": Numberlong (2) } }, "Database": { "Acquirecount": { "R": Numberlong (1) } }, "Collection": { "Acquirecount": { "R": Numberlong (1) } } }, "nreturned": 0, "ResponseLength": 110, "Protocol": "Op_command", "Millis": 0, "Execstats": { "Stage": "Collscan", "Filter": { "$and": [ ] }, "nreturned": 0, "Executiontimemillisestimate": 0, "Works": 2, "Advanced": 0, "Needtime": 1, "Needyield": 0, "SaveState": 0, "Restorestate": 0, "IsEOF": 1, "Invalidates": 0, "Direction": "Forward", "Docsexamined": 0 }, "TS": Isodate ("2016-06-04t03:56:35.706z"), "Client": "127.0.0.1", "AllUsers": [ ], "User": ""}{ "OP": "Query", "NS": "Test.users", "Query": { "Find": "Users", "Filter": { "Name": "wolfy66666" } }, "Keysexamined": 0, "Docsexamined": 866283, "Cursorexhausted":true, "Keyupdates": 0, "Writeconflicts": 0, "Numyield": 6767, "Locks": { "Global": { "Acquirecount": { "R": Numberlong (13536) } }, "Database": { "Acquirecount": { "R": Numberlong (6768) } }, "Collection": { "Acquirecount": { "R": Numberlong (6768) } } }, "Nreturned": 1, "ResponseLength": 160, "Protocol": "Op_command", "Millis": 339, "Execstats": { "Stage": "Collscan", "Filter": { "Name": { "$eq": "wolfy66666" } }, "Nreturned": 1, "Executiontimemillisestimate": 310, "Works": 866285, "Advanced": 1, "Needtime": 866283, "Needyield": 0, "SaveState": 6767, "Restorestate": 6767, "IsEOF": 1, "Invalidates": 0, "Direction": "Forward", "Docsexamined": 866283 }, "TS": Isodate ("2016-06-04t03:57:10.206z"), "Client": "127.0.0.1", "AllUsers": [ ], "User": ""}
Use the following command to view the latest records
Db.system.profile.find (). Sort ({$natural:-1})
There is also a more concise way to view
Show profile
This command can view the last 5 records
The information content provided by profile is explained
TS: When the command is executed.
Millis: Execution time, in milliseconds.
OP: what operation.
Query: Sets the search criteria.
Nreturned: The number of bars returned.
docsexamined: Number of document scan strips.
Summarize
The above lists the use of the profile, as well as several commonly used analysis results to explain. Interested can use additions and deletions to practice practiced hand, try.
[MongoDB] Profiling Performance Analysis