MongoDB MEM Management

NEVER USE MONGODB ON PRODUCTION.

Here the guy also meet my problem: https://news.ycombinator.com/item?id=5704572

This post is about MongoDB memory management mechanism.
All it’s using is Page Cache of System.

This is a good experience report: https://speakerdeck.com/mitsuhiko/a-year-of-mongodb

This URL gives you more details
https://www.mongodb.com/presentations/mongodb-memory-management-demystified

OK, this post is just for me to check commands to use, to management MongoDB.

1. connect

1
mongo 127.0.0.1:20001/${DB_NAME} -u ${USER_NAME} -p ${PASSWORD}

2. db working set

Use this to determine how much memory do you need of your working set under your current database.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
> > db.runCommand({serverStatus: 1, workingSet: 1}).tcmalloc.formattedString
------------------------------------------------
MALLOC: 7614540648 ( 7261.8 MiB) Bytes in use by application
MALLOC: + 236527616 ( 225.6 MiB) Bytes in page heap freelist
MALLOC: + 657428112 ( 627.0 MiB) Bytes in central cache freelist
MALLOC: + 53399376 ( 50.9 MiB) Bytes in transfer cache freelist
MALLOC: + 17635000 ( 16.8 MiB) Bytes in thread cache freelists
MALLOC: + 27570336 ( 26.3 MiB) Bytes in malloc metadata
MALLOC: ------------
MALLOC: = 8607101088 ( 8208.4 MiB) Actual memory used (physical + swap)
MALLOC: + 603160576 ( 575.2 MiB) Bytes released to OS (aka unmapped)
MALLOC: ------------
MALLOC: = 9210261664 ( 8783.6 MiB) Virtual address space used
MALLOC:
MALLOC: 326169 Spans in use
MALLOC: 56 Thread heaps in use
MALLOC: 8192 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.

3. db.stats()

1
2
3
4
5
6
7
8
9
10
11
12
13
> db.stats()
{
"db" : "xxxx", // this has been covered due to classification info
"collections" : 4,
"objects" : 39817003,
"avgObjSize" : 113.20676571262784,
"dataSize" : 4507554130,
"storageSize" : 2112126976,
"numExtents" : 0,
"indexes" : 12,
"indexSize" : 2265329664,
"ok" : 1
}
0%