Heap growth

337 views
Skip to first unread message

Pavel Perekalov

unread,
Mar 7, 2018, 6:26:35 PM3/7/18
to mongodb-user
Hi all!
I'm using community version of MongoDB 3.4.13 and have an issue with high memory usage.

Database size is about 5GB
PRIMARY> show dbs;
admin          
0.000GB
local          1.374GB
mydb          
4.814GB


Configured wiredTiger cache size is 512MB:
PRIMARY> db.serverStatus().wiredTiger.cache['maximum bytes configured']
536870912


MongoDB memory usage (rss) is 12GB(!):
PRIMARY> db.serverStatus().mem
{
   
"bits" : 64,
   
"resident" : 12077,
   
"virtual" : 13658,
   
"supported" : true,
   
"mapped" : 0,
   
"mappedWithJournal" : 0
}


tcmalloc tells me that heap size is 20 times bigger than allocated memory:
PRIMARY> db.serverStatus().tcmalloc.generic
{
   
"current_allocated_bytes" : 620202152,
   
"heap_size" : NumberLong("12861964288")
}

PRIMARY
> db.serverStatus().tcmalloc.tcmalloc.formattedString
------------------------------------------------
MALLOC
:      622027856 (  593.2 MiB) Bytes in use by application
MALLOC
: +  11991433216 (11435.9 MiB) Bytes in page heap freelist
MALLOC
: +      8663824 (    8.3 MiB) Bytes in central cache freelist
MALLOC
: +      1076992 (    1.0 MiB) Bytes in transfer cache freelist
MALLOC
: +      8042912 (    7.7 MiB) Bytes in thread cache freelists
MALLOC
: +     57303296 (   54.6 MiB) Bytes in malloc metadata
MALLOC
:   ------------
MALLOC
: =  12688548096 (12100.7 MiB) Actual memory used (physical + swap)
MALLOC
: +    230719488 (  220.0 MiB) Bytes released to OS (aka unmapped)
MALLOC
:   ------------
MALLOC
: =  12919267584 (12320.8 MiB) Virtual address space used
MALLOC
:
MALLOC
:          20252              Spans in use
MALLOC
:            120              Thread heaps in use
MALLOC
:           4096              Tcmalloc page size
------------------------------------------------
Call ReleaseFreeMemory() to release freelist memory to the OS (via madvise()).
Bytes released to the OS take up virtual address space but no physical memory.


I haven't found correlations with memory usage growth and my workload (it's almost read only: up to 20 qps) yet.
It reproduces with any secondary of this replicaset (when it becomes primary) and with another mongodb servers.

I've attached db.serverStatus output(running every minute from start) with heapProfilingEnabled.

I run MongoDB in containers, so OOM is my huge problem now.
Does anyone have any ideas about what's going on?

Kevin Adistambha

unread,
May 2, 2018, 1:06:53 AM5/2/18
to mongodb-user

Hi Pavel

It’s been some time since you posted this. Are you still having issues with high memory usage?

Please note that WiredTiger cache size is only part of MongoDB memory usage. Outside of WiredTiger cache, MongoDB uses memory for connections (~1 MB per connection), in-memory sorting, aggregation use, etc. So if you have a lot of active connections into the database, memory usage by the threads handling the connections could add up.

Having said that, could you please try upgrading to the latest in the 3.4 series (currently 3.4.14)? There were many improvements between 3.4.13 and 3.4.14, some of them involving memory usage. It is possible that upgrading may alleviate the memory pressure you’re seeing. Please see Upgrade to the Latest Revision of MongoDB for procedures.

Best regards
Kevin

Reply all
Reply to author
Forward
0 new messages