概述
MongoDB优化(三) ---- system profile
前面两章记录如何修改默认的配置和索引调优的策略,本章将介绍mongo自带的分析工具profiling
准备工作
启动mongoDB切换至需要的库
./mongo
--username xx
--password xx
--port xx
--authenticationDatabase xxx
> use IDP2
查看当前的profile等级
> db.getProfilingLevel() 0
返回 0 代表当前没有设置profiling等级。
关于等级官方有解释,传送门:https://docs.mongodb.com/manual/reference/method/db.setProfilingLevel/
这里简单解释一下一共有 0, 1, 2三个等级,
默认等级是0,代表关闭
等级1,如果设置了时间则会记录比设置时间慢的请求,无设置则默认慢查询100ms
等级2,记录所有的查询请求
这里查询过滤100ms以上的请求来观察
> db.setProfilingLevel(1,100) { "was" : 0, "slowms" : 100, "ok" : 1 }
接下来就可以开始性能请求操作了
操作完成后,我们需要先关闭掉profiling再做操作,避免因为手工操作引起的记录
> db.setProfilingLevel(0) { "was" : 1, "slowms" : 100, "ok" : 1 }
> db.system.profile.count()
992
可以看到一共记录了992条数据,再查看详细的数据都是操作了什么很慢。
> db.system.profile.find({}, {ns:1,op:1,millis:1,query:1}) { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 165 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 188 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 172 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 190 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 161 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 157 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 160 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 151 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 140 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 132 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 133 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 107 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 119 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 126 } { "op" : "query", "ns" : "IDP2.OrganizationUnit", "query" : { "find" : "OrganizationUnit", "filter" : { "archived" : false, "externalId" : "OU0 992164adf79adf35b7ab795565d736a627b4zz74clb", "enterpriseUuid" : "5beed120546802f0a35fff3998eae8fa8JzyFIiIHxt" }, "ntoreturn" : -1 }, "millis" : 149 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 219 } { "op" : "query", "ns" : "IDP2.OrganizationUnit", "query" : { "find" : "OrganizationUnit", "filter" : { "_id" : "zjs_3_1353", "enterpriseUuid" : "5beed120546802f0a35fff3998eae8fa8JzyFIiIHxt" }, "ntoreturn" : -1 }, "millis" : 145 } { "op" : "query", "ns" : "IDP2.OrganizationUnit", "query" : { "find" : "OrganizationUnit", "filter" : { "archived" : false, "enterpriseUuid" : "5beed120546802f0a35fff3998eae8fa8JzyFIiIHxt", "rootNode" : true }, "ntoreturn" : -1 }, "millis" : 150 } { "op" : "insert", "ns" : "IDP2.SessionEnterpriseUser", "millis" : 103 } { "op" : "query", "ns" : "IDP2.ApplicationInformation", "query" : { "find" : "ApplicationInformation", "filter" : { "archived" : false, "applicationUuid" : "2a4a8b5fd24e77907d0938a5db8d8352NcfqwsKNOoy", "enterpriseId" : "cs5" }, "ntoreturn" : -1 }, "millis" : 171 } Type "it" for more > it { "op" : "insert", "ns" : "IDP2.OrganizationUnitUDGroup", "millis" : 105 } { "op" : "insert", "ns" : "IDP2.AuditLog", "millis" : 130 } { "op" : "insert", "ns" : "IDP2.OrganizationUnit", "millis" : 123 } { "op" : "insert", "ns" : "IDP2.OrganizationUnitOU", "millis" : 115 } { "op" : "insert", "ns" : "IDP2.UDGroup", "millis" : 135 } { "op" : "query", "ns" : "IDP2.PSMemberRole", "query" : { "find" : "PSMemberRole", "filter" : { "memberUuid" : "0ffd3ff5f9ebc6107968ebe5150cffdbxiZj1vfaG1I" } }, "millis" : 115 } { "op" : "insert", "ns" : "IDP2.UDGroup", "millis" : 294 } { "op" : "insert", "ns" : "IDP2.UDGroup", "millis" : 202 } { "op" : "insert", "ns" : "IDP2.UDGroup", "millis" : 159 } { "op" : "insert", "ns" : "IDP2.AuditLog", "millis" : 162 } { "op" : "insert", "ns" : "IDP2.UDGroup", "millis" : 157 } { "op" : "insert", "ns" : "IDP2.UDGroup", "millis" : 141 } { "op" : "insert", "ns" : "IDP2.UDGroup", "millis" : 238 } { "op" : "insert", "ns" : "IDP2.UDGroup", "millis" : 328 } { "op" : "insert", "ns" : "IDP2.UDGroup", "millis" : 131 } { "op" : "insert", "ns" : "IDP2.UDGroup", "millis" : 308 } { "op" : "update", "ns" : "IDP2.OrganizationUnit", "query" : { "_id" : "f90263c56f5257226f0e28e25f5f6198Wb1GsbgeuLe" }, "millis" : 169 } { "op" : "insert", "ns" : "IDP2.UDGroup", "millis" : 218 } { "op" : "query", "ns" : "IDP2.ApplicationInformation", "query" : { "find" : "ApplicationInformation", "filter" : { "applicationUuid" : "2a4a8b5fd24e77907d0938a5db8d8352NcfqwsKNOoy", "enterpriseId" : "cs5" }, "ntoreturn" : -1 }, "millis" : 120 } { "op" : "insert", "ns" : "IDP2.UDGroup", "millis" : 140 } Type "it" for more
可以通过继续输入 “it”来查看更多。
{ "op" : "insert", --- 操作是插入
"ns" : "IDP2.UDGroup", ---- 表是UGGroup
"millis" : 140 } ---- 花费时间是140ms
接下来就根据不同的操作查看表是不是建立了合理的索引,如果没有则对索引进行修改即可。
当我们分析完成以后通过
db.system.profile.drop()
来清空这些捕捉到的数据,清空之前需要先关闭profiling。
posted on
2018-06-28 10:37
破碎的不是梦 阅读(
...) 评论(
...)
编辑
收藏
转载于:https://www.cnblogs.com/pill/p/9237464.html
最后
以上就是干净电源为你收集整理的MongoDB优化(三) ---- system profile的全部内容,希望文章能够帮你解决MongoDB优化(三) ---- system profile所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复