[SERVER-9415] MongoDB only uses small amount of RAM Created: 22/Apr/13 Updated: 26/Sep/17 Resolved: 03/Dec/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Performance |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Blocker - P1 |
| Reporter: | jeff liu | Assignee: | Adam Comerford |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
4-CPU 16GB RAM CenOS 6.2 VM |
||
| Issue Links: |
|
||||||||||||||||
| Operating System: | ALL | ||||||||||||||||
| Participants: | |||||||||||||||||
| Case: | (copied to CRM) | ||||||||||||||||
| Description |
|
I've a single Mongo instance running on a 4-CPU 16GB RAM CenOS 6.2 VM. It's running very slowly mostly of the time. Here is the mongostat output:
The command line options are: --rest --fork --master --oplogSize=22770 --port 27017 --dbpath /data/mongodb/dbdata/ --logpath /data/logs/mongodb.log --auth Here is the top output:
The weird thing is MongoDB consistently only consumes only 2.6G of RAM! However, the output from 'top' shows all 16GB RAM is used up. A couple of other observations:
The DB has one large collection having about 50 million documents; all other collections are small. The DB serves about 2000 users frontended by Tomcat (which has almost no load). I cannot figure out why it uses less than 3GB of RAM while the system has 16GB. |
| Comments |
| Comment by David Brailovsky [ 06/Dec/13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Any plans to "fix" this issue? That is, have a good way of understanding how much RAM mongodb is actually using? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Adam Comerford [ 03/Dec/13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Going to resolve this as "Works as Designed" - this is not fixed, but we're pretty happy that we have proven that data is actually still in RAM and that this is basically a reporting issue due to how journaling works rather than any data actually being evicted from memory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Adam Comerford [ 08/May/13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Jim, It means, that at least in our testing, that the low resident memory "cliff" we saw was essentially a red herring. Even with resident memory extremely low, subsequent operations on the data revealed that it was in fact still in RAM (in the filesystem cache), hence when we accessed the data the page faults stayed low and speed was not an issue. With a slow system, then the resident memory behavior is likely focusing attention in the wrong place. Aside from the low resident memory, take a look at faulting (mongostat/MMS) and in particular combine that with disk IO metrics (IOStat and munin-node in MMS) to see if you are hitting disk a lot, and if you are, how performant the disk is. Next up would be lock percentage - if you are over-subscribing a database, that can also cause slowness. Your blockdev output shows a readahead setting of 256 - that is 128k. Unless you have massive documents, that won't be terribly efficient loading randomly distributed documents into the filesystem cache. For most cases I would recommend lowering that to 32 (16k) unless you have those aforementioned large documents. Note that RA changes require a process restart to take effect. I would look at tweaks here before throwing more RAM at the issue - at least you will know you are efficiently using RAM before you look at adding more. Adam | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jim Gow [ 07/May/13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Adam, thanks for the update. Does this mean everything is normal and there is nothing else we need to do? Now the system is rather slow. To improve that, should we add more RAM, or start sharding? As I mentioned earlier, our single largest collection has about 50 million documents. Jim | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Adam Comerford [ 06/May/13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Update here, we have figured out that the drop off in resident memory when you introduce writes into the equation is down to how we implement journaling, and the private remapping of memory. For more info on that, take a look here: http://www.kchodorow.com/blog/2012/10/04/how-mongodbs-journaling-works/ The good news is that we can also confirm that the data is still in memory (in the filesystem cache), it is just not counted against the mongod process at that point. Subsequent reads of the data have produced no hard page faults, meaning that the data were still available in memory when requested. This is essentially the same state data is in when you run the touch command - it makes the readahead system call and pages the data requested into the filesystem cache, however (as with resident memory post-remapping) the data is not assigned to the mongod process specifically and does not count toward the resident memory of that process. Once an explain() or similar read behavior is run to actively access a large section of data, resident memory will increase. Adam | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Adam Comerford [ 23/Apr/13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The good news here is that we have recreated the behavior (a large amount of resident memory immediately dropping off when a workload is introduced). Once we have more information on this one, we well share it here. Adam. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Adam Comerford [ 23/Apr/13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
From the mongodb-user thread:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by jeff liu [ 22/Apr/13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
One more observation. I tried to modify our application so that the most frequent write operations are temporarily disabled, and then mongod is able to consume around 11GB of RAM. Once I re-enabled those write operations in the app, mongod RAM consumption goes down to 2.6GB immediately. The output from "blockdev --report" is:
The data is on /dev/xvdd1, which is a virtualized storage volume. The journal and logs are on /dev/xvda3, which is RAID5.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Daniel Pasette (Inactive) [ 22/Apr/13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Jeff, can you tell me what your average document size is on your largest database? Can you post db.stats()? As shown by free, your cache is full, however, mongodb only counts the documents that it has accessed, so if readahead is high, you might be filling your cache with documents you haven't accessed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by jeff liu [ 22/Apr/13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
free -tm gives the following:
|