Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB Out of Memory

MongoDB is crashing. When I open the mongodb.log file, I get:

$ tail /var/log/mongodb/mongodb.log
Sat Jan 25 03:06:56.153 [initandlisten] connection accepted from 127.0.0.1:58492 #63331 (263 connections now open)
Sat Jan 25 03:07:02.694 out of memory, printing stack and exiting:
0xde05e1 0x6cf37e 0x12129fd 0xc490c3 0xc4404e 0xc44196 0xda4913 0xda53e4 0xe28e69 0x7f5cbaa19e9a 0x7f5cb9d2c3fd 
 /usr/bin/mongod(_ZN5mongo15printStackTraceERSo+0x21) [0xde05e1]
 /usr/bin/mongod(_ZN5mongo14my_new_handlerEv+0x3e) [0x6cf37e]
 /usr/bin/mongod(_Znam+0x6d) [0x12129fd]
 /usr/bin/mongod(_ZNK5mongo3Top8cloneMapERNS_9StringMapINS0_14CollectionDataEEE+0x83) [0xc490c3]
 /usr/bin/mongod(_ZN5mongo9Snapshots12takeSnapshotEv+0x4e) [0xc4404e]
 /usr/bin/mongod(_ZN5mongo14SnapshotThread3runEv+0x66) [0xc44196]
 /usr/bin/mongod(_ZN5mongo13BackgroundJob7jobBodyEN5boost10shared_ptrINS0_9JobStatusEEE+0xc3) [0xda4913]
 /usr/bin/mongod(_ZN5boost6detail11thread_dataINS_3_bi6bind_tIvNS_4_mfi3mf1IvN5mongo13BackgroundJobENS_10shared_ptrINS7_9JobStatusEEEEENS2_5list2INS2_5valueIPS7_EENSD_ISA_EEEEEEE3runEv+0x74) [0xda53e4]
 /usr/bin/mongod() [0xe28e69]
 /lib/x86_64-linux-gnu/libpthread.so.0(+0x7e9a) [0x7f5cbaa19e9a]
 /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7f5cb9d2c3fd]

This question sounds similar: MongoDB: out of memory But his problem was a ulimit issue. My memory settings are already unlimited.

Others had particular issues with .skip() or .limit() given unreasonably large values, but that's not happening here.

Anyone know what might be wrong?

like image 948
Erik Buchanan Avatar asked Jan 25 '14 09:01

Erik Buchanan


1 Answers

The MongoDB docs recommend having enough swap space for MongoDB, despite it not being a requirement: http://docs.mongodb.org/manual/administration/production-notes/#ProductionNotes-Swap

I'm using Windows Azure hosting, and I discovered that their virtual servers don't have swap space by default:

$ sudo swapon -s
Filename                Type        Size    Used    Priority

(Azure defaults to no swap space: Part 1 & Part 2)

So I found a guide to creating a swap file: https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04

And it solved my problem!

Notes:

  1. The guide says Ubuntu 12.04, but the same steps worked for me on 13.10.
  2. You should use a swap file around half the size of your RAM, not the 512MB used in the guide.

I hope this helps others solve this problem.

like image 126
Erik Buchanan Avatar answered Sep 21 '22 22:09

Erik Buchanan