我在设置MongoDB
的最大传入连接时遇到问题。
我运行了ulimit -n 1000000
并重新启动了mongo,我的MMS信息中心中的最后一次ping显示:
"maxIncomingConnections": 1000000,
但是:
"connections": {
"current": 701,
"totalCreated": 712,
"available": 118
},
正如您所见,current
+ available
是819
,这是系统默认的(80% from 1024)
。
有什么想法吗?
答案 0 :(得分:1)
我不知道您运行ulimit命令的用户,但请记住,这仅适用于当前环境中的当前用户。
更好的方法是在/etc/security/limits.conf
中设置打开文件限制,如下所示:
# Max is 64k anyway, and there is a hard limit
# of 20k connection in MongoDB anyway
# 40k open files should be more than enough
# unless you have _very_ large disks and a _shitload_ of datafiles
mongodb soft nofiles 40000
mongodb hard nofiles 64000
# Make sure we don't get throttled CPU wise
mongodb soft cpu unlimited
mongodb hard cpu unlimited
# This is kind of useless, since the maximum size
# a file created by MongoDB is 2GB for now
# but it is save and the docs say to do so
mongodb soft fsize -1
mongodb hard fsize -1
# We don't want our resident stack to be limited...
mongodb soft rss -1
mongodb hard rss -1
# ... nor the address space
mongodb soft as -1
mongodb hard as -1
# Last but not least, we want the number of processes at a reasonable limit
mongodb soft noproc 32000
mongodb hard noproc 32000
但是,如果您手动启动MongoDB,这只是一个后备,因为upstart脚本应该设置相应的限制。添加这些值后,需要重新启动iirc。那么,可用连接数应该增加。
注意:请记住,每个连接在服务器上分配大约1MB的堆栈,然后不能用于在RAM中保存索引和数据。