Limits MongoDB memory usage
Because MongoDB's memory is managed by the system's virtual memory, MongoDB does not interfere with memory management. This can simplify Mongo's work, but the memory usage of Mongo cannot be controlled at the same time.
Is it really uncontrollable? You can useUlimitTo control the virtual address space of a user process.
Ulimit controls the memory size of all processes. How can we control MongoDB? In fact, it can be changed. We use a user in our own Linux to run MongoDB, and other programs run with other users. Because ulimit can restrict specified user resources.
Use ulimit-a to view all the resources that can be modified
118 ~ > Ulimit-A @ Root
-T:CPU
Time(Seconds) Unlimited
-F:FileSize (blocks) Unlimited
-D: Data seg size (Kbytes) Unlimited
-S: stack size (Kbytes) 8192
-C: Core File size (blocks) 0
-M: resIDEnt
SetSize (Kbytes) Unlimited
-U: Processes 1024.
-N: file descriptors 1024
-L: locked-in-memory size (Kb) 64
-V:DdRESS space (Kb) Unlimited
-X: File locks Unlimited
-I: Pending signaLs15661
-Q: bytes in posix msg queues 819200
-E: Max nice 0
-R: Max RT priority 0
Here we modify the ulimit-V: Address Space (Kb) option, that is, the maximum virtual address space of the user process.
We create a new user, CB, before launching mongod.
Ulimit-V 1000000: Change the maximum virtual address space to 1 GB.
Then run mongod port 10000 and execute the data insertion script.
Use the root user again. Do not modify ulimit any more. Enable another mongod port as 20000.
Port 1000 restricts the virtual address space. Port 2000 is unrestricted. The effect is obvious! Http://www.linuxso.com/linuxpeixun/14251.html