Maximum Connections dont increase even after specifying in mongod.conf.

1,268 views
Skip to first unread message

Kaustubh Padegaonkar

unread,
Feb 18, 2011, 7:27:03 AM2/18/11
to mongod...@googlegroups.com
This is my mongod.conf file:


And this is the output of db.serverStatus():


Even though I have set the maxConns parameter to 3000, I only see total connections (current + available) equaling to 819 in the serverStatus. What gives?

Thanks.

Kaustubh Padegaonkar.



Nat

unread,
Feb 18, 2011, 7:34:24 AM2/18/11
to mongod...@googlegroups.com
Your ulimit setting may be too low. What is the output of?
ulimit -a
From: Kaustubh Padegaonkar <thetu...@gmail.com>
Date: Fri, 18 Feb 2011 17:57:03 +0530
Subject: [mongodb-user] Maximum Connections dont increase even after specifying in mongod.conf.
--
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.

Kaustubh Padegaonkar

unread,
Feb 18, 2011, 7:39:34 AM2/18/11
to mongod...@googlegroups.com
Hi Nat,

this is the output of ulimit -a

$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) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) unlimited
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Nat

unread,
Feb 18, 2011, 7:40:53 AM2/18/11
to mongod...@googlegroups.com
You need to change your ulimit -n option before you start mongod.

From: Kaustubh Padegaonkar <thetu...@gmail.com>
Date: Fri, 18 Feb 2011 04:39:34 -0800 (PST)
Subject: Re: [mongodb-user] Maximum Connections dont increase even afterspecifying in mongod.conf.

Scott Hernandez

unread,
Feb 18, 2011, 7:44:00 AM2/18/11
to mongod...@googlegroups.com
What version of the server have you installed and on what os/distro?
There was a problem with the startup script on debian/ubuntu where the
startup script always set the open files limit to 1024 (and the
connections were limited to 80% ~ 820).

Kaustubh Padegaonkar

unread,
Feb 18, 2011, 7:52:59 AM2/18/11
to mongod...@googlegroups.com
@Scott

I am using a large 64bit Debian Squeeze 6.0 instance on the Amazon cloud. Mongodb is version 1.6.5. The OP of uname -a is

Linux domU-12-31-39-16-EE-C6 2.6.21.7-2.fc8xen-ec2-v1.0 #1 SMP Tue Sep 1 10:25:30 EDT 2009 x86_64 GNU/Linux

Scott Hernandez

unread,
Feb 18, 2011, 8:05:36 AM2/18/11
to mongod...@googlegroups.com
Can you post the contents of /etc/init/mongodb.conf?

Kaustubh Padegaonkar

unread,
Feb 18, 2011, 8:16:05 AM2/18/11
to mongod...@googlegroups.com
Sure, here you are:

# Ubuntu upstart file at /etc/init/mongodb.conf

pre-start script
    mkdir -p /var/lib/mongodb/
    mkdir -p /var/log/mongodb/
end script

start on runlevel [2345]
stop on runlevel [06]

script
  ENABLE_MONGODB="yes"
  if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi
  if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec  /usr/bin/mongod -- --config /etc/mongodb.conf; fi
end script

Kaustubh Padegaonkar

unread,
Feb 18, 2011, 8:20:43 AM2/18/11
to mongod...@googlegroups.com
My apologies, there isnt such a file in the server, I accidently gave this file from the local machine. In fact, there isnt a init folder in the production server.

Scott Hernandez

unread,
Feb 18, 2011, 8:23:22 AM2/18/11
to mongod...@googlegroups.com
Yeah, can you upgrade your package and take the new config file it
provides. It will include a line for open files after the mkdir lines;
you can alter that as you see fit. It should look like this: "limit
nofile 9000 9000" with soft/hard limits as the two numbers.
http://upstart.ubuntu.com/wiki/Stanzas#limit

Scott Hernandez

unread,
Feb 18, 2011, 8:26:40 AM2/18/11
to mongod...@googlegroups.com
Then is the production server not debian squeeze? How did you install
the server?

Kaustubh Padegaonkar

unread,
Feb 18, 2011, 8:30:53 AM2/18/11
to mongod...@googlegroups.com
No, the production server is Debain Squeeze, the local machine was Ubuntu. Unfortunately, I cant update the package, on the server. I will get the file from a local install, and check.

Kaustubh Padegaonkar

unread,
Feb 18, 2011, 11:13:15 AM2/18/11
to mongod...@googlegroups.com
I upgraded to 1.7.5, and there was no change in the file. I didnt get the upstart limits in the file.

Eugene

unread,
Mar 29, 2011, 1:49:01 PM3/29/11
to mongodb-user
I have the same problem. Currently using Ubuntu Maverick, MongoDB
version 1.6.5. I'm using it for logging by piping Apache logs into a
Perl script using the Perl MongoDB driver. The connections steadily
increase and after about an hour, the MongoDB stops accepting new
connections.

Current max connections available is 1024. I changed settings in /etc/
security/limits.conf to allow 65000 soft and hard limit, which shows
up when I do ulimit -a. However, even after setting up maxConns in
the upstart script (and adding a limit nofile line in there), MongoDB
still won't use the new file descriptor limit and will only use 1024
as the max files. I also added session required pam_limits.so to /etc/
pam.d/common-session.

upstart script:

pre-start script
PORT=27027
mkdir -p /var/lib/mongodb${PORT}
mkdir -p /var/log/mongodb
limit nofile 65000 65000
limit nproc 65000 65000
end script

start on runlevel [2345]
stop on runlevel [06]

script
PORT=27027
ENABLE_MONGODB="yes"
if [ -e /var/lib/mongodb${PORT}/mongod.lock ]; then rm /var/lib/
mongodb${PORT}/mongod.lock; fi
if [ ! -d /var/lib/mongodb${PORT} ]; then mkdir -p /var/lib/mongodb$
{PORT}; fi
chown -R mongodb:mongodb /var/lib/mongodb${PORT}
if [ "x$ENABLE_MONGODB" = "xyes" ]; then
exec start-stop-daemon --start --quiet --chuid mongodb \
--pidfile /var/lib/mongodb${PORT}/${PORT}.pid \
--exec /usr/bin/mongod -- \
--port ${PORT} \
--dbpath /var/lib/mongodb${PORT} \
--logpath /var/log/mongodb/mongodb${PORT}.log \
--logappend \
--maxConns = 50000 \
--replSet oascluster \
--oplogSize 200 \
--rest
fi
end script

respawn

respawn limit 20 30


Am I missing something?

Thanks,
Eugene

On Feb 18, 5:44 am, Scott Hernandez <scotthernan...@gmail.com> wrote:
> What version of the server have you installed and on what os/distro?
> There was a problem with the startup script on debian/ubuntuwhere the
> startup script always set the open files limit to 1024 (and theconnectionswere limited to 80% ~ 820).
>
> On Fri, Feb 18, 2011 at 4:27 AM, Kaustubh Padegaonkar
>
> <thetuxra...@gmail.com> wrote:
> > This is my mongod.conf file:
> >http://pastie.org/1578363
>
> > And this is the output of db.serverStatus():
> >http://pastie.org/1578367
>
> > Even though I have set the maxConns parameter to 3000, I only see total
> >connections(current + available) equaling to 819 in the serverStatus. What

Erez Zarum

unread,
Mar 29, 2011, 1:55:51 PM3/29/11
to mongod...@googlegroups.com
Do you also have one set for /etc/pam.d/su? 
Have you set the limits for the mongodb user as well or only for root?
try sudo -u mongodb ulimit -a (or under any user mongodb is running on)

Eugene

unread,
Mar 29, 2011, 2:21:44 PM3/29/11
to mongodb-user
I hadn't had one set for /etc/pam.d/su, but have set that now.
Restarted the server, still 1024 max file descriptors for MongoDB.

sudo -u mongodb ulimit -a complains with "command not found" unless I
don't prefix the "sudo -u mongodb".

Thanks for the quick reply.

On Mar 29, 10:55 am, Erez Zarum <e...@icinga.org.il> wrote:
> Do you also have one set for /etc/pam.d/su?
> Have you set the limits for the mongodb user as well or only for root?
> try sudo -u mongodb ulimit -a (or under any user mongodb is running on)
>

Eugene

unread,
Mar 29, 2011, 2:23:21 PM3/29/11
to mongodb-user
Oh, as for limits, I set it for every user since the only purpose for
the server is to be a MongoDB server.

On Mar 29, 10:55 am, Erez Zarum <e...@icinga.org.il> wrote:
> Do you also have one set for /etc/pam.d/su?
> Have you set the limits for the mongodb user as well or only for root?
> try sudo -u mongodb ulimit -a (or under any user mongodb is running on)
>

Eugene

unread,
Mar 29, 2011, 5:56:46 PM3/29/11
to mongodb-user
All of the modifications I made to limits.conf and /etc/pam.d did
their job, as the max file descriptors went up. However, it turns out
that for some reason, upstarts scripts were ignoring these maximums
(or maybe it was the start-stop daemon) and the max was left at 1024.
I tried solving it with the limit no file line in the pre-start script
section, but it seems MongoDB 1.6.5 doesn't work with the limit nofile
line. I needed to put ulimit -n X (where X is the file descriptors you
want) just after the script keyword.

script
ulimit -n 60000
PORT=27027
...

I guess the method using the pre-start block is for later versions of
MongoDB.

Also for note, MongoDB has a hard limit of 20,000 connections, so it
doesn't matter if you set file descriptors higher than that.

Another thing learned: starting and stopping using upstart scripts is
not the same as REstarting. Starting and stopping threw errors on the
limit nofile command, whereas restarting did not.

Hope that helps someone from pounding their head against the wall for
the better part of two days like me.

On Mar 29, 11:23 am, Eugene <ehdyc...@gmail.com> wrote:
> Oh, as for limits, I set it for every user since the only purpose for
> the server is to be a MongoDB server.
>
> On Mar 29, 10:55 am, Erez Zarum <e...@icinga.org.il> wrote:
>
> > Do you also have one set for /etc/pam.d/su?
> > Have you set the limits for the mongodb user as well or only for root?
> > try sudo -u mongodb ulimit -a (or under any user mongodb is running on)
>
> > On Tue, Mar 29, 2011 at 7:49 PM, Eugene <ehdyc...@gmail.com> wrote:
> > > I have the same problem.  Currently usingUbuntuMaverick, MongoDB
> > > version 1.6.5.  I'm using it for logging by piping Apache logs into a
> > > Perl script using the Perl MongoDB driver.  Theconnectionssteadily
> > > increase and after about an hour, the MongoDB stops accepting new
> > >connections.
>
> > > Current maxconnectionsavailable is 1024.  I changed settings in /etc/
> > > security/limits.conf to allow 65000 soft and hard limit, which shows
> > > up when I do ulimit -a.  However, even after setting up maxConns in
> > > theupstartscript (and adding a limit nofile line in there), MongoDB

Adewole Ogunyadeka

unread,
Jan 27, 2016, 4:42:01 AM1/27/16
to mongodb-user
I have this same problem. When I run the command db.serverStatus().connections on command line I get {"current":4, "available": 999996, "totalCreated": NumberLong(367)}. However, my Mongodb is been run on a windows machine. How can I get to the config file to adjust this or can I run it in command line. If yes, what are the commands.

Thank you

Stephen Steneker

unread,
Jan 27, 2016, 6:08:15 AM1/27/16
to mongodb-user

On Wednesday, 27 January 2016 20:42:01 UTC+11, Adewole Ogunyadeka wrote:

I have this same problem. When I run the command db.serverStatus().connections on command line I get {“current”:4, “available”: 999996, “totalCreated”: NumberLong(367)}. However, my Mongodb is been run on a windows machine. How can I get to the config file to adjust this or can I run it in command line. If yes, what are the commands.

Hi Adewole,

You definitely have a different issue as this thread is almost 5 years old and specific to older versions (and non-Windows O/S) for MongoDB deployment ;-). Your serverStatus output indicates a total of 1,000,000 connections (999,996 available) so you don’t seem to be in need of increasing the connection limit.

If you do have a specific question, please start a new thread with relevant details for your environment including:

  • specific version of MongoDB you are using
  • type of deployment (standalone, replica set, or sharded cluster)
  • O/S version
  • error message or question

Thanks,
Stephen

Reply all
Reply to author
Forward
0 new messages