How to change max connections in mongod

2,544 views
Skip to first unread message

Sebastian Dahlgren

unread,
Jul 7, 2011, 8:14:12 AM7/7/11
to mongodb-user
Hi!

How can we change the number of max connections in mongod? We are
starting mongod with:

/usr/local/mongodb/bin/mongod --dbpath /mnt/mongodb/data --logpath /
mnt/mongodb/logs/mongodb.log --logappend --maxConns 4000 --rest --
replSet primarySet1

And still db.serverStatus() is reporting:

"connections" : {
"current" : 16,
"available" : 803
}

We saw that it could relate to the number of file descriptors.
Currently we have 8192.

mongo@md-05:~$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 16382
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 8192
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 1024
cpu time (seconds, -t) unlimited
max user processes (-u) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

Any help appreciated!
Sebastian

Andrew Kryzhyk

unread,
Jul 7, 2011, 8:28:07 AM7/7/11
to mongod...@googlegroups.com
Hi!

Try to increase the number of open files in limits.conf and restart
the server process.
As far as I remember - somewhere were mentioned that it depends on it.

2011/7/7 Sebastian Dahlgren <sebastian...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

--
% rm God
rm: God nonexistent

Sebastian Dahlgren

unread,
Jul 7, 2011, 9:05:46 AM7/7/11
to mongodb-user
Hi!

Thanks for a quick reply. Unfortunately it does not help. We have
tried to increase the number of file descriptors to 16384, but it
doesn't change.

The strange thing here is that we have another cluster running MongoDB
1.8.1, with the same OS configuration and about 6600 in max
connections. In this environment, we are starting mongo with

/usr/local/mongodb/bin/mongod --dbpath /mnt/mongodb/data --logpath /
mnt/mongodb/logs/mongodb.log --logappend --rest --replSet primarySet1

Br
Sebastian

On Jul 7, 2:28 pm, Andrew Kryzhyk <mail2kand...@gmail.com> wrote:
> Hi!
>
> Try to increase the number of open files in limits.conf and restart
> the server process.
> As far as I remember - somewhere were mentioned that it depends on it.
>
> 2011/7/7 Sebastian Dahlgren <sebastian.dahlg...@gmail.com>:
> > For more options, visit this group athttp://groups.google.com/group/mongodb-user?hl=en.

Scott Hernandez

unread,
Jul 7, 2011, 9:35:44 AM7/7/11
to mongod...@googlegroups.com
This is an environment issue and probably related to how you create the process.

What OS/Distro? How are you starting mongod? Is there an init script?
Are you using 1.8.1 on all servers?

Sebastian Dahlgren

unread,
Jul 7, 2011, 9:44:40 AM7/7/11
to mongodb-user
OS: Debian 6
Mongo: 1.8.2 (sharded environment with 2 replSets with 3 nodes in
each)
Starting mongo with: /usr/local/mongodb/bin/mongod --dbpath /mnt/
mongodb/data --logpath /mnt/mongodb/logs/mongodb.log --logappend --
rest --replSet primarySet1

But have also tried appending --maxConns 4000 to the start up.

The same scripts, ulimits and start parameters gave us 6600
connections on 1.8.1.

Sebastian Dahlgren

unread,
Jul 7, 2011, 9:50:28 AM7/7/11
to mongodb-user
I do agree, it is probably environment. But what parameters is taken
into consideration?

The log is at least saying that it decreases my request from 4000 to
819:

Thu Jul 7 13:48:41 [initandlisten] --maxConns too high, can only
handle 819

/Sebastian

On Jul 7, 3:44 pm, Sebastian Dahlgren <sebastian.dahlg...@gmail.com>
wrote:

Andrew Kryzhyk

unread,
Jul 7, 2011, 9:59:37 AM7/7/11
to mongod...@googlegroups.com
From which user you are running mongodb processes?
Also are the limits set to all users or only to specific users/groups?

2011/7/7 Sebastian Dahlgren <sebastian...@gmail.com>:

> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Scott Hernandez

unread,
Jul 7, 2011, 10:00:37 AM7/7/11
to mongod...@googlegroups.com
That is because the process was started with a limit of 1024 open
files. Mongod takes 80% for connections = 819.

How are you starting the process? Are you using an upstart job, or
init script? If so, what does it look like?

Sebastian Dahlgren

unread,
Jul 7, 2011, 10:03:28 AM7/7/11
to mongodb-user
It is running as user mongo:

mongo 25051 1 0 13:48 ? 00:00:05 /usr/local/mongodb/bin/
mongod --dbpath /mnt/mongodb/data --logpath /mnt/mongodb/logs/
mongodb.log --logappend --maxConns 4000 --rest --replSet primarySet1

And the /etc/security/limits.conf looks like (I usually have 8192, but
trying with 16834 atm):

# MongoDB recommended nofiles
mongo soft nofile 16384
mongo hard nofile 16384
#mongo soft nofile 8192
#mongo hard nofile 8192
mongo soft stack 1024
mongo hard stack 1024

When logging in with the mongo user and running ulimit -a I get:

mongo@md-05:~$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 16382
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 16384
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 1024
cpu time (seconds, -t) unlimited
max user processes (-u) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

So those parameters do have effect.

On Jul 7, 3:59 pm, Andrew Kryzhyk <mail2kand...@gmail.com> wrote:
> From which user you are running mongodb processes?
> Also are the limits set to all users or only to specific users/groups?
>
> 2011/7/7 Sebastian Dahlgren <sebastian.dahlg...@gmail.com>:

Sebastian Dahlgren

unread,
Jul 7, 2011, 10:14:04 AM7/7/11
to mongodb-user
Sounds sound :)

The start script is available at http://avkod.at/test/mongod

On Jul 7, 4:03 pm, Sebastian Dahlgren <sebastian.dahlg...@gmail.com>

Sebastian Dahlgren

unread,
Jul 7, 2011, 10:15:08 AM7/7/11
to mongodb-user
And it's a init script, located in /etc/init.d/mongod.

On Jul 7, 4:14 pm, Sebastian Dahlgren <sebastian.dahlg...@gmail.com>
wrote:
> Sounds sound :)
>
> The start script is available athttp://avkod.at/test/mongod

Andrew Kryzhyk

unread,
Jul 7, 2011, 10:34:56 AM7/7/11
to mongod...@googlegroups.com
Hi!

Sorry for the stupid question, but did you restart the mongod process
after changing the limits?

2011/7/7 Sebastian Dahlgren <sebastian...@gmail.com>:

> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Sebastian Dahlgren

unread,
Jul 7, 2011, 10:45:01 AM7/7/11
to mongodb-user
I did :) (over and over and over)

On Jul 7, 4:34 pm, Andrew Kryzhyk <mail2kand...@gmail.com> wrote:
> Hi!
>
> Sorry for the stupid question, but did you restart the mongod process
> after changing the limits?
>
> 2011/7/7 Sebastian Dahlgren <sebastian.dahlg...@gmail.com>:

Sebastian Dahlgren

unread,
Jul 7, 2011, 10:47:53 AM7/7/11
to mongodb-user
When starting directly as the mongod user, without the start script it
works fine. So there is something in that scripts behavior. Strangely
enough we are using the very same script with the earlier MongoDB
version and that works.

I'll dig deeper into that script.


On Jul 7, 4:45 pm, Sebastian Dahlgren <sebastian.dahlg...@gmail.com>

Andrew Kryzhyk

unread,
Jul 7, 2011, 2:51:23 PM7/7/11
to mongod...@googlegroups.com
Do you have limits set for root user? Can you show the output from
ulimit -a from root?

2011/7/7 Sebastian Dahlgren <sebastian...@gmail.com>:

> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Scott Hernandez

unread,
Jul 7, 2011, 6:07:07 PM7/7/11
to mongod...@googlegroups.com
That is probably it if you are running the script as root and then
changing to the mongo user in a child (forked) process.

Sebastian Dahlgren

unread,
Jul 8, 2011, 8:22:43 AM7/8/11
to mongodb-user
Thanks for all your input! The solution I did was to explicitly add
the ulimit values I needed in the init script (with inheritance from /
etc/default/mongod).

Cheers
Sebastian

On 8 Juli, 00:07, Scott Hernandez <scotthernan...@gmail.com> wrote:
> That is probably it if you are running the script as root and then
> changing to the mongo user in a child (forked) process.
>
>
>
>
>
>
>
> On Thu, Jul 7, 2011 at 2:51 PM, Andrew Kryzhyk <mail2kand...@gmail.com> wrote:
> > Do you have limits set for root user? Can you show the output from
> > ulimit -a from root?
>
> > 2011/7/7 Sebastian Dahlgren <sebastian.dahlg...@gmail.com>:
> >>> > >> > > --...
>
> läs mer »
Reply all
Reply to author
Forward
0 new messages