I have a MongoDB server running on an inexpensive Linux VPS (1 x 2.0GHz CPU and 1GB RAM).
It's been about a day now and the output of db.stats()
looks reasonable.
db.stats()
{
"db" : "app",
"collections" : 11,
"objects" : 2067,
"avgObjSize" : 238.20416061925496,
"dataSize" : 492368,
"storageSize" : 1007616,
"numExtents" : 18,
"indexes" : 9,
"indexSize" : 138992,
"fileSize" : 16777216,
"nsSizeMB" : 16,
"dataFileVersion" : {
"major" : 4,
"minor" : 5
},
"extentFreeList" : {
"num" : 5,
"totalSize" : 286720
},
"ok" : 1
}
I can project the number of days until I exceed my disk space.
I know (from the FAQs) "MongoDB automatically uses all free memory on the machine as its cache."
How should I determine whether I need more RAM or CPU capacity?
Although it's application dependent, is either RAM or CPU generally more important?
Is there anything returned by db.runCommand( { serverStatus: 1, workingSet: 1 } )
that I should pay particular attention to?
MongoDB requires approximately 1 GB of RAM per 100.000 assets. If the system has to start swapping memory to disk, this will have a severely negative impact on performance and should be avoided.
You can inspect mem. mapped to check the amount of mapped memory that mongod is using. If this value is greater than the amount of system memory, some operations will require a page faults to read data from disk.
NUMA (Non-Uniform Memory Access) Architecture Non-Uniform Memory Access is a recent memory architecture that takes into account the locality of caches and CPUs for lower latency. Unfortunately, MongoDB is not “NUMA-aware” and leaving NUMA setup in the default behavior can cause severe memory in-balance.
Indexes are resource-intensive: even with compression in the MongoDB WiredTiger storage engine, they consume RAM and disk. As fields are updated, associated indexes must be maintained, incurring additional CPU and disk I/O overhead.
How should I determine whether I need more RAM or CPU capacity?
It's very important to have enough memory so your indexes and the data can fit in the memory to achieve good performance. If your workingSet doesn't fit in the memory you will have a lot of page faults. Page faults occur when MongoDB requires data that is not loaded in the physical memory and it must read from virtual memory (i.e. disk). Accessing disk instead of memory will degrade your performance significantly as accessing the disk is orders of magnitude slower than accessing data in the memory. SSD disks are good, but they are still much slower than RAM.
People often forget that open connections also require memory. On Linux, memory overhead for each connection is about 10 MB (on older versions like v1.8). Since v1.9 this overhead was changed to be around 1MB according to this JIRA ticket. So if you have 100 open connections, that will that will roughly translate to 1GB (on older) and 100MB (on newer versions) of memory usage (this number could have changed with most recent MongoDB versions, so YMMV). You can check the connections in the output of your serverStatus
command to see info about the current / available number of connections.
I recommend that you read the MongoDB diagnostics.
Although it's application dependent, is either RAM or CPU generally more important?
Having a better CPU is important for tasks that are CPU intensive like: scanning and sorting, updating and rebalancing indexes, map-reduce, aggregation framework commands and server-side JavaScript. Having a better CPU will help with those tasks, but if you don't have enough memory and you're constantly reading from the disk, your performance will be degraded.
Is there anything returned by db.runCommand( { serverStatus: 1, workingSet: 1 } ) that I should pay particular attention to?
Command serverStatus is a very useful tool to collect the statistics about your server and analyze your server stats.
In output of the serverStatus
command you should pay attention to:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With