Logging and Profiling MongoDB Performance Tuning Part 3
Posted By : Abhimanyu Singh | 29-Jun-2015
In this blog , I am going to discuss about logging and profiling of mongodb. Logging
MongoDB log slow queries in text file which take more than 100ms . How we can access it first stop the services of mongodb .
Now in your terminal execute the following statement
sudo mongod dbpath /var/lib/mongodb /* /var/lib/mongodb is path of mongodb on my system */
The above line will start the service of mongodb . Now open another terminal and start the mongodb shell using command “mongo” . you will execute your queries here and you will find those queries which take more than 100s listing on first terminal .
Profilier It writes, entries document to system.profile for any query that takes time longer than specified period of time It has three level
level 0 this is default level and profiler is off.
level 1 this is level used to logged when query takes more than specified period of time.
level 2 you will logged the all queries . It can be used for purpose to see database traffic on your system.
Below is the command which will logged those queries which take time more than 2ms.
mongod dbpath /var/lib/mongodb profile 1 slowms 2
Above command is used similar to what we have explained in logging but it will used for logging those queries which will take more than specified period of time , in my case it is 2ms.
command to find all the queries which take more time
db.system.profile.find();
It will give details of all the slow queries . It is capped collection , fixed size collection so it recycle space to store the recent query details only if there is no space left .
some queries that is really useful and we can performed on system.profile
db.system.profile.find{(millis:{$gt:1}}).sort({ts:1})
It will return all those queries details which took more than 1 milli seconds, sorted by timestamp
db.system.profile.find({ns:’/school/student’}).sort({ts:1})
The above query will return all the entries in system.profile which is performed on student collection of school database sorted by timestamp.
MongoTop
mongotop 3
This command will run at every three second and give high level view of mongodb where it is utilizing it maximum time . It give list of 5 collections where the mongodb is utilizing is maximum time sorted by time utilizing in descending order along with red and write time . It will help us to figure it which collections need indexing and with the help of logger and profiling we can determine the fields which we can use for indexing .
Mongostat
mongostat
this command give the system level information about the mongodb . query executing per second , insert etc .The one field idx_miss% it is important for us , it is used to know when a query is executing having index on the field where the index is used or not. This is all for mongodb performance tuning .
I hope it will help you .
Thanks
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Abhimanyu Singh
Abhimanyu is an seasoned technologist . He always keeps himself ahead in embracing and adapting new technologies/frameworks to solve business problems. He specialise in Blockchain technology , Video Content Management & enterprise software .