important config note on running MongoDB in production on Linux

1,741 views
Skip to first unread message

dwight_10gen

unread,
Jun 29, 2011, 1:07:12 PM6/29/11
to mongodb-user
The mongod process uses a thread per connection. Each thread has a
stack. Typically on Linux the default stack size is 8MB. That's a
lot of memory if you have 1,000 or 10,000 connections -- enough that
it may cause your server to become very slow. Linux seems to not like
to swap out the unused portion of the stacks, despite mongod typically
using a small fraction of that 8MB stack space.

To check your number of connections, run in the mongo shell:

db.serverStatus().connections

If it is a small number, you are fine. If a larger number, we
recommend you lower the default stack size using ulimit. The syntax
is:

ulimit -s 1024

which will set the stack size to 1MB instead of 8MB.

In MongoDB v2.0 this will happen automatically.

Mike K

unread,
Jun 29, 2011, 2:46:06 PM6/29/11
to mongod...@googlegroups.com
Thanks Dwight!

Do you (or anyone else) know the equivalent to put into /etc/sysctl.conf so that this limit persists across reboots?

Thanks,
Mike

Zack Radick

unread,
Jun 29, 2011, 3:00:59 PM6/29/11
to mongod...@googlegroups.com
For Ubuntu you can edit /etc/security/limits.conf.
--Zack

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-user/-/V4nTGS5m5C0J.

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.

axlfu

unread,
Jun 29, 2011, 8:11:11 PM6/29/11
to mongodb-user
Do I have to restart mongod?
If not , what about the old collections' stack size, are they still
8m?

axlfu

unread,
Jun 29, 2011, 8:53:55 PM6/29/11
to mongodb-user
How to Estimate the stack size,What are included?

On Jun 30, 1:07 am, dwight_10gen <dwi...@10gen.com> wrote:

Eliot Horowitz

unread,
Jun 29, 2011, 9:39:29 PM6/29/11
to mongod...@googlegroups.com
stack size is a linux process wide setting, not collection.
After you change, you have to restart mongod.

You can find the current by doing "ulimit -s"

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.

付玉

unread,
Jun 29, 2011, 10:01:41 PM6/29/11
to mongod...@googlegroups.com
How do I know if my set is ok?
Is this just a buffer?

2011/6/30 Eliot Horowitz <elioth...@gmail.com>

Dwight Merriman

unread,
Jun 30, 2011, 12:37:52 AM6/30/11
to mongod...@googlegroups.com
yes a buffer, the thread's stack, for each thread -- there is a thread per connection.

Sergei Tulentsev

unread,
Jun 30, 2011, 11:39:18 AM6/30/11
to mongod...@googlegroups.com
> db.serverStatus().connections
{ "current" : 29, "available" : 790 }

Do I have 29 connections (with their stacks) and I can create 790 more?
Or those 790 are just sitting idle?
Best regards,
Sergei Tulentsev

Nat

unread,
Jun 30, 2011, 12:15:24 PM6/30/11
to mongod...@googlegroups.com
That's right. It means you can create 790 more. They're not idle connections.
From: Sergei Tulentsev <sergei.t...@gmail.com>
Date: Thu, 30 Jun 2011 19:39:18 +0400
Subject: Re: [mongodb-user] Re: important config note on running MongoDB in production on Linux
Message has been deleted

mathias

unread,
Jul 29, 2011, 11:52:06 AM7/29/11
to mongodb-user


On Jun 29, 8:11 pm, axlfu <freesearc...@gmail.com> wrote:
> Do I have to restart mongod?
> If not , what about the old collections' stack size, are they still
> 8m?


This is about connections, not collections.

Eliot Horowitz

unread,
Jul 12, 2012, 12:10:45 AM7/12/12
to mongod...@googlegroups.com
Right, that's normal.
So since its min(1,10) it'll be 1, which is good.

On Thu, Jul 12, 2012 at 12:07 AM, gmz <gen...@gmail.com> wrote:
> hi
> I am using mongodb 2.0.4, as "2.0 Release Notes" saying the default stack
> size would be "the lesser of the system setting or 1MB".
> but as follows, I found the stack size is 10240K in the process limits file,
> is it true?
>
> Production: [mba@mg3sh] ~$ ps aux|grep mongo
> mba 15594 0.1 29.5 80910156 14623684 ? Sl Apr09 206:15
> ./bin/mongod --port 27038 --replSet shard03/10.16.1.240:27038 --fork
> --dbpath /data1/mba-data/shard03/ --oplogSize 20480 --logpath
> /data1/mba-logs/shard03/mongod.log --logappend
>
> Production: [mba@mg3sh] ~$ ulimit -a|grep stack
> stack size (kbytes, -s) 10240
> Production: [mba@mg3sh] ~$ cat /proc/15594/limits |grep stack
> Max stack size 10485760 unlimited bytes
> Production: [mba@mg3sh] ~$
>
> gmz
> 7/12 2012
>
> 在 2011年6月30日星期四UTC+8上午1时07分12秒,dwight_10gen写道:
> --
> 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
> See also the IRC channel -- freenode.net#mongodb

gmz

unread,
Jul 12, 2012, 12:28:27 AM7/12/12
to mongod...@googlegroups.com
but I see the stack size is 10M in the process limits file, as follows. why?

Production: [mba@mg3sh] ~$ cat /proc/15594/limits |grep stack
Max stack size            10485760             unlimited            bytes     
10485760 bytes is 10M.

在 2012年7月12日星期四UTC+8下午12时10分45秒,Eliot Horowitz写道:

Eliot Horowitz

unread,
Jul 12, 2012, 12:29:59 AM7/12/12
to mongod...@googlegroups.com
Thats the system setting.
mongo can control it at thread creation time.
>> > mongodb-user...@googlegroups.com
>> > See also the IRC channel -- freenode.net#mongodb
>
> --
> 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

gmz

unread,
Jul 12, 2012, 12:42:54 AM7/12/12
to mongod...@googlegroups.com
I see, thanks.

在 2012年7月12日星期四UTC+8下午12时29分59秒,Eliot Horowitz写道:
>> > See also the IRC channel -- freenode.net#mongodb
>
> --
> 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

Rendy Bambang Junior

unread,
Sep 16, 2014, 11:11:04 PM9/16/14
to mongod...@googlegroups.com, dwi...@10gen.com
 Hi Dwight,

Does it still apply now? I noticed that it is not there as recommendation or notes in current mongodb manual http://docs.mongodb.org/manual/reference/ulimit/

I find another blog about this matter https://blog.serverdensity.com/mongodb-connection-overhead/, however it is published at 2011 as well, so I am not really sure whether it still applies now.

Thanks!
Rendy

Stephen Steneker

unread,
Sep 16, 2014, 11:16:04 PM9/16/14
to mongod...@googlegroups.com
On Wednesday, 17 September 2014 13:11:04 UTC+10, Rendy Bambang Junior wrote:
Does it still apply now? I noticed that it is not there as recommendation or notes in current mongodb manual http://docs.mongodb.org/manual/reference/ulimit/

I find another blog about this matter https://blog.serverdensity.com/mongodb-connection-overhead/, however it is published at 2011 as well, so I am not really sure whether it still applies now.

Hi Rendy,

As noted in the original thread you replied to (from 2011) the stack size limit was changed for MongoDB 2.0 to the lesser of the system setting or 1MB:
 http://docs.mongodb.org/manual/release-notes/2.0/#default-stack-size

Regards,
Stephen
Reply all
Reply to author
Forward
0 new messages