MongoDB can't set 'maxIncomingConnections'

2.4k views Asked by At

I have a problem setting the maximum incoming connections for my MongoDB.

I ran ulimit -n 1000000 and restarted mongo, the last ping in my MMS dashboard shows:

"maxIncomingConnections": 1000000,

however:

"connections": {
    "current": 701,
    "totalCreated": 712,
    "available": 118
},

as you can see current + available is 819 which is the default (80% from 1024) from system.

Any ideas?

1

There are 1 answers

2
Markus W Mahlberg On

I don't know as which user you ran the ulimit command, but keep in mind that this only is valid for the current user in the current environment.

A better approach is to set the open file limit in /etc/security/limits.conf like this:

# 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

However, this is only a fallback in case you start MongoDB manually, since the upstart script should set the according limits. After adding these values, a reboot is needed iirc. The number of available connections should increase, then.

Note: Keep in mind that each connection gets about 1MB of stack allocated on the server, which then can not be used for holding indices and data within RAM.