Recommended method Three, the simplest and easiest to view
A: If MongoDB has been running for a long time, the view mongod.log is very large, can not open to view the corresponding information
#ps-ef|grep Mongod
Find the PID of the corresponding Mongod process
Then kill-sigusr1 the PID so that Mongod will regenerate a log file
> Db.setprofilinglevel (2);
{"was": 0, "OK": 1}
> Db.getprofilinglevel ()
The above italic level can take 0,1,2 three values, they say the meaning is as follows:
0– not open
--Record slow command (default = >100ms)
--Record all orders
View in the log log of the Mongod node after profiling is turned on
Cat Mongod.log
or tail-300 Mongod.log.
Two.
In the future you have encountered this problem of some slow operation directly from the database to open the 5th level log under Small data, to see if it visited those tables, directly to see if there is no index in the PY
In general, as long as the system is not paralyzed, no index is a direct cause of slow
Db.admincommand ({logrotage:1})
KILL-SIGUSR1 xxx
Db.setloglevel (1, "query")
Db.setloglevel (1, "command")
Three
In order to locate the exclusive MongoDB problem as soon as possible, please help crawl the MongoDB log if you find out which operation or parallel operation is slow.
is divided into two aspects:
Profiling: If we define all database operations slower than 100ms to be slow, do the following:
Use MyDomain
Db.setprofilinglevel (1, 100), replace mydomain with the domain you tested
So all the slow operations will be shown here in Db.system.profile.
Db.setprofilinglevel (2) is the opening of all operation profiles, which can be experimentally used, or opened in a short time. But be sure to shut it down in time.
Show collections will see one more collection called System.profile.
Then Db.system.profile.find (). Pretty ()
LOG: You can see all the actions with Db.setloglevel (1,command), and the time of each operation will be recorded.
Remember to use Db.setloglevel (0,command) to change back after positioning.
MongoDB Enable profiling location problem