Why MongoDB release memory automatically.

835 views
Skip to first unread message

hu_jia...@hotmail.com

unread,
Mar 21, 2012, 2:51:31 AM3/21/12
to mongodb-user
I've always thought, MongoDB uses memory-mapped files and never
managed memory. But this week, a strange thing happened, every once in
a while (a few minutes), MongoDB automatically release Memory,
resulting slow query.

insert query update delete getmore command flushes mapped vsize
res faults locked % idx miss % qr|qw ar|aw netIn netOut conn
repl time
0 2 0 0 0 1 0 10.5g 21.8g
1.11g 0 0 0 0|1 3|0 638b 9k
6 M 11:28:35
0 2 0 0 0 1 0 10.5g 21.8g
1.11g 0 0 0 0|1 3|0 638b 9k
6 M 11:28:36
0 6 5 0 4 6 0 10.5g 21.8g
437m 1 6.5 0 0|1 3|0 18k 20k
6 M 11:28:37
0 4 0 0 0 1 0 10.5g 21.8g
448m 0 0 0 0|1 3|0 1k 11k
6 M 11:28:38


By the way, there is only MongoDB running on the server, so the
memory should be enough.

$ free -m
total used free shared buffers
cached
Mem: 32189 18699 13489 0 233
17353
-/+ buffers/cache: 1112 31077
Swap: 34175 0 34175

quwei...@sohu.com

unread,
Mar 21, 2012, 5:07:13 AM3/21/12
to mongodb-user
Limit RAM Usage
MongoDB is not designed to do that, it is designed for speed and
scalability.

If we wanted to run MongoDB on the same physical machine alongside
some web server and for example some application server like Django,
then we could ensure memory limits on each one by simply using
virtualization and putting each one in its own VE (Virtual
Environment). In the end we would thus have a web application made of
MongoDB, Django and for example Nginx, all running on the same
physical machine but being limited to whatever limits we set on each
VE they run in.



On 3月21日, 下午2时51分, "hu_jiajun1...@hotmail.com"

Scott Hernandez

unread,
Mar 21, 2012, 9:32:26 AM3/21/12
to mongod...@googlegroups.com
The operating system manages that cached memory for the memory mapped
files and can decide based on other programs memory usage that it must
release some, which can affect mongod.

http://mongodb.org/display/DOCS/Caching
http://www.mongodb.org/display/DOCS/Checking+Server+Memory+Usage

What other programs/servers are you running on the same system?

> --
> 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.
>

hu_jia...@hotmail.com

unread,
Mar 21, 2012, 9:24:22 PM3/21/12
to mongodb-user
thanks, Scott Hernandez!
I'm sure there is not other programs on the server. Only Mongodb.
I test mmap() last night, map 10 GB memory and OS never release.
Why OS release Mongodb but not my test program.

Scott Hernandez

unread,
Mar 21, 2012, 9:55:38 PM3/21/12
to mongod...@googlegroups.com
What does free -ltm show?

hu_jia...@hotmail.com

unread,
Mar 21, 2012, 11:08:52 PM3/21/12
to mongodb-user
$ free -ltm
total used free shared buffers
cached
Mem: 32189 19365 12823 0 268
17945
Low: 32189 19365 12823
High: 0 0 0
-/+ buffers/cache: 1152 31037
Swap: 34175 0 34175
Total: 66365 19365 46999

i think memory is enough.

every time when mongodb release memory, db will be locked in seconds.
OS release memory, why mongodb is locked ?

mapped vsize res faults locked %
8.03g 17.1g 988m 0 0
8.03g 17.1g 202m 0 3.6
8.03g 17.1g 285m 0 0

Yizhe Tang

unread,
Mar 23, 2012, 7:18:57 AM3/23/12
to mongod...@googlegroups.com
I met the same issue.
I've my mongo cluster running on 4 * 12 Ram machines. 
Each machine carries
 a primary           1.7G res ram
 a secondary       2.3G res ram
 an arbiter           19m  res ram
 a config node     450m res ram

no other memory consuming processes.
My program keeps hitting the cluster with random keys, and meets qps bottleneck. I think more res memory can solve the performance issue, but don't know why it stays low.
Will these mongo instances affect each other on the same machine?

thanks

> To unsubscribe from this group, send email to mongodb-user+unsubscribe@​googlegroups.com.

Scott Hernandez

unread,
Mar 23, 2012, 9:13:24 AM3/23/12
to mongod...@googlegroups.com
The lock% is the time spent in the write lock. If you are writing,
this will be non-zero.

You only have 8GB of mapped memory and the cache is much higher than
that. You have faults and that indicates that you basically have all
data in memory.

These numbers look fine.

Scott Hernandez

unread,
Mar 23, 2012, 9:14:05 AM3/23/12
to mongod...@googlegroups.com
Please create a new thread and post mongostat and free -ltm numbers
for each server which has data.

>> > mongodb-user...@googlegroups.com.


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

> --
> 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/-/rHoa0Sh_8iYJ.


>
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to

> mongodb-user...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages