{"id":1141,"date":"2011-12-02T10:11:00","date_gmt":"2011-12-02T02:11:00","guid":{"rendered":"\/?p=1141"},"modified":"2011-12-02T10:11:00","modified_gmt":"2011-12-02T10:11:00","slug":"1141","status":"publish","type":"post","link":"https:\/\/blog.vimge.com\/archives\/nosql\/1141.html","title":{"rendered":"MongoDB\u8fd0\u884c\u72b6\u6001\u3001\u6027\u80fd\u76d1\u63a7\uff0c\u5206\u6790"},"content":{"rendered":"
\u4f7f\u7528\u4efb\u4f55\u4e00\u4e2a\u4ea7\u54c1\uff0c\u5fc5\u4e0d\u53ef\u5c11\u7684\u4e00\u9879\u5de5\u4f5c\u5c31\u662f\u5bf9\u5b58\u50a8\u7684\u76d1\u63a7<\/a><\/span>\uff0c\u76d1\u63a7\u53ef\u4ee5\u8ba9\u4f60\u66f4\u4e86\u89e3\u5b58\u50a8\u7684\u8fd0\u4f5c\u65b9\u5f0f\uff0c\u8ba9\u4f60\u66f4\u65e9\u7684\u53d1\u73b0\u4f7f\u7528\u4e0a\u7684\u95ee\u9898\uff0c\u4e0b\u9762\u6587\u7ae0\u8f6c\u81ea\u6cdb\u57ce\u79d1\u6280\u6280\u672f\u535a\u5ba2<\/a>\uff0c\u5bf9MongoDB<\/a><\/span>\u7684\u76d1\u63a7\u505a\u4e86\u8be6\u7ec6\u6df1\u5165\u7684\u63a2\u8ba8\u3002\u63a8\u8350\u7ed9\u5404\u4f4d\u4f7f\u7528MongoDB\u7684\u670b\u53cb\u3002<\/p>\n \u539f\u6587\u94fe\u63a5\uff1atech.lezi.com<\/a><\/p>\n \u8fd9\u7bc7\u6587\u7ae0\u7684\u76ee\u7684\u662f\u8ba9\u4f60\u77e5\u9053\u600e\u4e48\u4e86\u89e3\u4f60\u6b63\u5728\u8fd0\u884c\u7684Mongdb\u662f\u5426\u5065\u5eb7\u3002<\/p>\n mongostat\u662fmongdb\u81ea\u5e26\u7684\u72b6\u6001\u68c0\u6d4b\u5de5\u5177\uff0c\u5728\u547d\u4ee4\u884c\u4e0b\u4f7f\u7528\u3002\u5b83\u4f1a\u95f4\u9694\u56fa\u5b9a\u65f6\u95f4\u83b7\u53d6mongodb\u7684\u5f53\u524d\u8fd0\u884c\u72b6\u6001\uff0c\u5e76\u8f93\u51fa\u3002\u5982\u679c\u4f60\u53d1\u73b0\u6570\u636e\u5e93\u7a81\u7136\u53d8\u6162\u6216\u8005\u6709\u5176\u4ed6\u95ee\u9898\u7684\u8bdd\uff0c\u4f60\u7b2c\u4e00\u624b\u7684\u64cd\u4f5c\u5c31\u8003\u8651\u91c7\u7528mongostat\u6765\u67e5\u770bmongo\u7684\u72b6\u6001\u3002<\/p>\n <\/p>\n \u5b83\u7684\u8f93\u51fa\u6709\u4ee5\u4e0b\u51e0\u5217\uff1a<\/p>\n \u7c7b\u4f3c\u4e8eMySQL\u7684slow log, MongoDB\u53ef\u4ee5\u76d1\u63a7\u6240\u6709\u6162\u7684\u4ee5\u53ca\u4e0d\u6162\u7684\u67e5\u8be2\u3002<\/p>\n <\/p>\n Profiler<\/a><\/span>\u9ed8\u8ba4\u662f\u5173\u95ed\u7684\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u5168\u90e8\u5f00\u542f\uff0c\u6216\u8005\u6709\u6162\u67e5\u8be2\u7684\u65f6\u5019\u5f00\u542f\u3002<\/p>\n \u67e5\u770bProfile\u65e5\u5fd7<\/p>\n 3\u4e2a\u5b57\u6bb5\u7684\u610f\u4e49<\/p>\n \u4e0d\u591a\u8bf4\uff0c\u6b64\u5904\u6709\u5b98\u65b9\u6587\u6863<\/a>\u3002\u6ce8\u610f\uff0c\u9020\u6210\u6ee1\u67e5\u8be2\u53ef\u80fd\u662f\u7d22\u5f15\u7684\u95ee\u9898\uff0c\u4e5f\u53ef\u80fd\u662f\u6570\u636e\u4e0d\u5728\u5185\u5b58\u9020\u6210\u56e0\u6b64\u78c1\u76d8\u8bfb\u5165\u9020\u6210\u3002<\/p>\n <\/a>Mongodb\u81ea\u5e26\u4e86Web\u63a7\u5236\u53f0\uff0c\u9ed8\u8ba4\u548c\u6570\u636e\u670d\u52a1\u4e00\u540c\u5f00\u542f\u3002\u4ed6\u7684\u7aef\u53e3\u5728Mongodb\u6570\u636e\u5e93\u670d\u52a1\u5668\u7aef\u53e3\u7684\u57fa\u7840\u4e0a\u52a01000\uff0c\u5982\u679c\u662f\u9ed8\u8ba4\u7684Mongodb\u6570\u636e\u670d\u52a1\u7aef\u53e3(Which is 27017)\uff0c\u5219\u76f8\u5e94\u7684Web\u7aef\u53e3\u4e3a28017<\/p>\n <\/p>\n \u8fd9\u4e2a\u9875\u9762\u53ef\u4ee5\u770b\u5230<\/p>\n \u53ef\u4ee5\u53c2\u8003\u53f3\u8fb9\u7684\u622a\u56fe<\/p>\n \u83b7\u53d6\u5f53\u524d\u6570\u636e\u5e93\u7684\u4fe1\u606f\uff0c\u6bd4\u5982Obj\u603b\u6570\u3001\u6570\u636e\u5e93\u603b\u5927\u5c0f\u3001\u5e73\u5747Obj\u5927\u5c0f\u7b49<\/p>\n \u83b7\u53d6\u670d\u52a1\u5668\u7684\u72b6\u6001<\/p>\n \u9700\u8981\u5173\u5fc3\u7684\u5730\u65b9\uff1a<\/p>\n Mongodb \u7684\u547d\u4ee4\u4e00\u822c\u5f88\u5feb\u5c31\u5b8c\u6210\uff0c\u4f46\u662f\u5728\u4e00\u53f0\u7e41\u5fd9\u7684\u673a\u5668\u6216\u8005\u6709\u6bd4\u8f83\u6162\u7684\u547d\u4ee4\u65f6\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7db.currentOp()\u83b7\u53d6\u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u64cd\u4f5c\u3002<\/p>\n \u5728\u6ca1\u6709\u8d1f\u8f7d\u7684\u673a\u5668\u4e0a\uff0c\u8be5\u547d\u4ee4\u57fa\u672c\u4e0a\u90fd\u662f\u8fd4\u56de\u7a7a\u7684<\/p>\n \u4ee5\u4e0b\u662f\u4e00\u4e2a\u6709\u8d1f\u8f7d\u7684\u673a\u5668\u4e0a\u5f97\u5230\u7684\u8fd4\u56de\u503c\u6837\u4f8b\uff1a<\/p>\n \u5b57\u6bb5\u540d\u5b57\u90fd\u80fd\u81ea\u89e3\u91ca\u3002\u5982\u679c\u4f60\u53d1\u73b0\u4e00\u4e2a\u64cd\u4f5c\u592a\u957f\uff0c\u628a\u6570\u636e\u5e93\u5361\u6b7b\u7684\u8bdd\uff0c\u53ef\u4ee5\u7528\u8fd9\u4e2a\u547d\u4ee4\u6740\u6b7b\u4ed6<\/p>\n <\/p>\n MongoDB Monitoring Service(MMS<\/a><\/span>)\u662fMongodb\u5382\u5546\u63d0\u4f9b\u7684\u76d1\u63a7\u670d\u52a1\uff0c\u53ef\u4ee5\u5728\u7f51\u9875\u548cAndroid\u5ba2\u6237\u7aef\u4e0a\u76d1\u63a7\u4f60\u7684MongoDB\u72b6\u51b5\u3002\u8bf7\u53c2\u8003<\/a>\u3002\u4e0d\u77e5\u9053\u662f\u4e60\u60ef\u8fd8\u662f\u4ec0\u4e48\u539f\u56e0\uff0cMMS\u63d0\u4f9b\u7684\u5728\u7ebf\u670d\u52a1\u603b\u89c9\u5f97\u6ca1\u6709\u63d0\u4f9b\u7a0b\u5e8f\u7531\u4f7f\u7528\u8005\u642d\u5efa\u73af\u5883\u9760\u8c31\uff0c\u6539\u5929\u4f53\u9a8c\u4e00\u4e0b\u6548\u679c\u518d\u62a5\u544a\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":" \u4f7f\u7528\u4efb\u4f55\u4e00\u4e2a\u4ea7\u54c1\uff0c\u5fc5\u4e0d\u53ef\u5c11\u7684\u4e00\u9879\u5de5\u4f5c\u5c31\u662f\u5bf9\u5b58\u50a8\u7684\u76d1\u63a7<\/a><\/span>\uff0c\u76d1\u63a7\u53ef\u4ee5\u8ba9\u4f60\u66f4\u4e86\u89e3\u5b58\u50a8\u7684\u8fd0\u4f5c\u65b9\u5f0f\uff0c\u8ba9\u4f60\u66f4\u65e9\u7684\u53d1\u73b0\u4f7f\u7528\u4e0a\u7684\u95ee\u9898\uff0c\u4e0b\u9762\u6587\u7ae0\u8f6c\u81ea\u6cdb\u57ce\u79d1\u6280\u6280\u672f\u535a\u5ba2<\/a>\uff0c\u5bf9MongoDB<\/a><\/span>\u7684\u76d1\u63a7\u505a\u4e86\u8be6\u7ec6\u6df1\u5165\u7684\u63a2<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1141"}],"collection":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/comments?post=1141"}],"version-history":[{"count":0,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1141\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/media?parent=1141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/categories?post=1141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/tags?post=1141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}mongostat<\/a><\/span>\u8be6\u89e3<\/h3>\n
\n
\u4f7f\u7528profiler<\/h3>\n
> use testswitched to db test> db.setProfilingLevel(2);{"was" : 0 , "slowms" : 100, "ok" : 1} \/\/ "was" is the old setting> db.getProfilingLevel()<\/pre>\n
> db.system.profile.find().sort({$natural:-1}){"ts" : "Thu Jan 29 2009 15:19:32 GMT-0500 (EST)" , "info" :"query test.$cmd ntoreturn:1 reslen:66 nscanned:0 query: { profile: 2 } nreturned:1 bytes:50" ,"millis" : 0} ...<\/pre>\n
\n
\u4f7f\u7528Web\u63a7\u5236\u53f0<\/h3>\n
\n
db.stat()<\/h3>\n
> use testswitched to db test> db.stats(){ "collections" : 9, "objects" : 4278845, "avgObjSize" : 224.56603031892953, "dataSize" : 960883236, "storageSize" : 1195438080, "numExtents" : 59, "indexes" : 13, "indexSize" : 801931264, "fileSize" : 6373244928, "ok" : 1}<\/pre>\n
db.serverStatus()<\/h3>\n
{ "version" : "1.6.5", "uptime" : 7208469, "uptimeEstimate" : 7138829, "localTime" : "Wed Oct 26 2011 22:23:07 GMT+0800 (CST)", "globalLock" : { "totalTime" : 7208469556704, "lockTime" : 4959693717, "ratio" : 0.000688036992871448, "currentQueue" : { "total" : 0, "readers" : 0, "writers" : 0 } }, "mem" : { "bits" : 64, "resident" : 3131, "virtual" : 6172, "supported" : true, "mapped" : 4927 }, "connections" : { "current" : 402, "available" : 2599 }, "extra_info" : { "note" : "fields vary by platform", "heap_usage_bytes" : 832531920, "page_faults" : 8757 }, "indexCounters" : { "btree" : { "accesses" : 2821726, "hits" : 2821725, "misses" : 1, "resets" : 0, "missRatio" : 3.543930204420982e-7 } }, "backgroundFlushing" : { "flushes" : 120133, "total_ms" : 73235923, "average_ms" : 609.6236920746173, "last_ms" : 1332, "last_finished" : "Wed Oct 26 2011 22:22:23 GMT+0800 (CST)" }, "cursors" : { "totalOpen" : 0, "clientCursors_size" : 0, "timedOut" : 238392 }, "repl" : { "ismaster" : true }, "opcounters" : { "insert" : 269351, "query" : 19331151, "update" : 14199331, "delete" : 1, "getmore" : 145575, "command" : 55982302 }, "asserts" : { "regular" : 0, "warning" : 0, "msg" : 0, "user" : 27, "rollovers" : 0 }, "ok" : 1}<\/pre>\n
\n
db.currentOp()<\/h3>\n
> db.currentOp(){ "inprog" : [ ] }<\/pre>\n
{ "opid" : "shard3:466404288", "active" : false, "waitingForLock" : false, "op" : "query", "ns" : "sd.usersEmails", "query" : { }, "client_s" : "10.121.13.8:34473", "desc" : "conn" },<\/pre>\n
> db.killOp("shard3:466404288")<\/pre>\n
MongoDB Monitoring Service<\/h3>\n