paulwong

          mongodb最大連接數(shù)修改

          在Linux平臺(tái)下,無(wú)論是64位或者32位的MongoDB默認(rèn)最大連接數(shù)都是819,WIN平臺(tái)不知道,估計(jì)也沒(méi)有人在 WIN平臺(tái)下使用MongoDB做生產(chǎn)環(huán)境

          [root@DELL113 mongodb-linux-i686-2.4.1]# ./bin/mongo 192.168.6.42
          MongoDB shell version: 2.4.1
          connecting to: 192.168.6.42/test
          > db.serverStatus().connections
          { "current" : 1, "available" : 818, "totalCreated" : NumberLong(1) }
          途中available顯示818少了一個(gè),表示空閑的。current表示已經(jīng)占用了的連接數(shù),兩數(shù)一加就等于819,如果我現(xiàn)在在連接一個(gè),那么available就是817,current就是2

          [root@DELL113 mongodb-linux-i686-2.4.1]# ./bin/mongo 192.168.6.42
          MongoDB shell version: 2.4.1
          connecting to: 192.168.6.42/test
          > db.serverStatus().connections
          { "current" : 1, "available" : 818, "totalCreated" : NumberLong(1) }
          > db.serverStatus().connections
          { "current" : 2, "available" : 817, "totalCreated" : NumberLong(2) }
          819個(gè)連接數(shù)對(duì)于一般的站點(diǎn)我認(rèn)為已經(jīng)夠用,并且都是現(xiàn)連現(xiàn)取現(xiàn)斷。但這個(gè)連接數(shù)也可以修改,只要在啟動(dòng)的時(shí)候加入--maxConns即可

          服務(wù)器啟動(dòng)

          [root@lee mongodb-linux-x86_64-2.4.1]# ./bin/mongod --dbpath=/root/db --maxConns=2000
          Wed Apr 3 11:06:21.905 [initandlisten] MongoDB starting : pid=2812 port=27017 dbpath=/root/db 64-bit host=lee
          Wed Apr 3 11:06:21.957 [initandlisten] db version v2.4.1
          Wed Apr 3 11:06:21.957 [initandlisten] git version: 1560959e9ce11a693be8b4d0d160d633eee75110
          Wed Apr 3 11:06:21.957 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
          Wed Apr 3 11:06:21.957 [initandlisten] allocator: tcmalloc
          Wed Apr 3 11:06:21.957 [initandlisten] options: { dbpath: "/root/db", maxConns: 2000 }
          Wed Apr 3 11:06:21.982 [initandlisten] journal dir=/root/db/journal
          Wed Apr 3 11:06:21.982 [initandlisten] recover : no journal files present, no recovery needed
          Wed Apr 3 11:06:22.297 [initandlisten] preallocateIsFaster=true 2.62
          Wed Apr 3 11:06:22.717 [initandlisten] --maxConns too high, can only handle 819
          Wed Apr 3 11:06:22.724 [initandlisten] waiting for connections on port 27017
          Wed Apr 3 11:06:22.725 [websvr] admin web console waiting for connections on port 28017
          Wed Apr 3 11:06:25.126 [initandlisten] connection accepted from 192.168.4.86:53917 #1 (1 connection now open)
          查詢最大連接數(shù)

          [root@DELL113 mongodb-linux-i686-2.4.1]# ./bin/mongo 192.168.6.42
          MongoDB shell version: 2.4.1
          connecting to: 192.168.6.42/test
          > db.serverStatus().connections
          { "current" : 1, "available" : 818, "totalCreated" : NumberLong(1) }

          發(fā)現(xiàn)還是819?其實(shí)是Linux默認(rèn)進(jìn)程能打開(kāi)最大文件數(shù)有關(guān),可以通過(guò)ulimit 解決

          [root@lee mongodb-linux-x86_64-2.4.1]# ulimit -n 2500
          [root@lee mongodb-linux-x86_64-2.4.1]# ./bin/mongod --dbpath=/root/db --maxConns=2000
          Wed Apr 3 11:11:07.013 [initandlisten] MongoDB starting : pid=2930 port=27017 dbpath=/root/db 64-bit host=lee
          Wed Apr 3 11:11:07.013 [initandlisten] db version v2.4.1
          Wed Apr 3 11:11:07.013 [initandlisten] git version: 1560959e9ce11a693be8b4d0d160d633eee75110
          Wed Apr 3 11:11:07.013 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
          Wed Apr 3 11:11:07.013 [initandlisten] allocator: tcmalloc
          Wed Apr 3 11:11:07.013 [initandlisten] options: { dbpath: "/root/db", maxConns: 2000 }
          Wed Apr 3 11:11:07.031 [initandlisten] journal dir=/root/db/journal
          Wed Apr 3 11:11:07.031 [initandlisten] recover : no journal files present, no recovery needed
          Wed Apr 3 11:11:07.170 [initandlisten] waiting for connections on port 27017
          Wed Apr 3 11:11:07.171 [websvr] admin web console waiting for connections on port 28017
          Wed Apr 3 11:11:10.076 [initandlisten] connection accepted from 192.168.4.86:53161 #1 (1 connection now open)
          再查看最大連接數(shù),搞定

          [root@DELL113 mongodb-linux-i686-2.4.1]# ./bin/mongo 192.168.6.42
          MongoDB shell version: 2.4.1
          connecting to: 192.168.6.42/test
          > db.serverStatus().connections
          { "current" : 1, "available" : 1999, "totalCreated" : NumberLong(1) }

          關(guān)于ulimit的更多知識(shí)大家可以去網(wǎng)上檢索檢索

          posted on 2014-06-10 21:50 paulwong 閱讀(544) 評(píng)論(0)  編輯  收藏 所屬分類: MONGODB

          主站蜘蛛池模板: 康乐县| 绥中县| 丹阳市| 遂川县| 黎平县| 上犹县| 时尚| 行唐县| 神木县| 许昌县| 清苑县| 光泽县| 巴林左旗| 越西县| 乌恰县| 淳安县| 阜新| 高安市| 万州区| 平泉县| 曲靖市| 麻阳| 无极县| 贵港市| 兴宁市| 河源市| 叙永县| 淳安县| 中西区| 固安县| 县级市| 东城区| 易门县| 孟村| 萨嘎县| 呼伦贝尔市| 高邑县| 平舆县| 泾源县| 凤凰县| 华蓥市|