關於MongoDB最大串連數的查看與修改

來源:互聯網
上載者:User

標籤:ulimit   shel   creat   roo   server   edit   查看   data-   通過   

 

一. MongoDB串連數

在Linux平台下,無論是64位或者32位的MongoDB預設最大串連數都是819,WIN平台不知道,估計也沒有人在 WIN平台下使用MongoDB做生產環境

[[email protected] mongodb-3.0.4]# ./bin/mongo
MongoDB shell version: 3.0.4
connecting to: test
> use admin
switched to db admin
> db.auth(‘user‘,‘password‘);
1
> db.serverStatus().connections;
{ "current" : 1, "available" : 818, "totalCreated" : NumberLong(2) }

上文available顯示818少了一個,表示閒置。current表示已經佔用了的串連數,兩數一加就等於819,如果我現在在串連一個,那麼available就是817,current就是2

[[email protected] mongodb-3.0.4]# ./bin/mongo
MongoDB shell version: 3.0.4
connecting to: test
> exit
bye
[[email protected] mongodb-3.0.4]# ./bin/mongo 192.168.5.215
MongoDB shell version: 3.0.4
connecting to: 192.168.5.215/test
> use admin
switched to db admin
> db.auth(‘al_user‘,‘123456‘);
1
> db.serverStatus().connections;
{ "current" : 2, "available" : 817, "totalCreated" : NumberLong(3) }

819個串連數對於一般的網站我認為已經夠用,並且都是現連現取現斷。但這個串連數也可以修改,只要在啟動的時候加入--maxConns即可

 

二. 修改MongoDB串連數

[[email protected] mongodb-3.0.4]# ./bin/mongod  --maxConns=41942

MongoDB shell version: 3.0.4
connecting to: test

查看mongo日誌

[[email protected] mongodb-3.0.4]# vim ./log/mongo.log

2016-04-22T12:02:43.669+0800 I CONTROL  [initandlisten] options: { net: { maxIncomingConnections: 41942 }, 

> db.serverStatus().connections;
{ "current" : 1, "available" : 818, "totalCreated" : NumberLong(2) }

發現還是819?其實是Linux預設進程能開啟最大檔案數有關,可以通過ulimit 解決

[[email protected] mongodb-3.0.4]# ulimit -n 41942

關於ulimit的更多知識大家可以去網上檢索檢索

再查看最大串連數

[[email protected] mongodb-3.0.4]# ./bin/mongod  --maxConns=41942

> use admin
switched to db admin
> db.auth(‘user‘,‘password‘);
1

> db.serverStatus().connections;
{ "current" : 1, "available" : 41941, "totalCreated" : NumberLong(1) }

搞定!

 

關於MongoDB最大串連數的查看與修改

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.