Cgroup limit MongoDB process memory size _mongodb

Source: Internet
Author: User
Tags mongoclient mongodb

For example, limit the memory size of the MongoDB.

mkdir/cgroup/memory/test/ 
echo 50M >/cgroup/memory/test/memory.limit_in_bytes 
echo 50M >/cgroup/ Memory/test/memory.memsw.limit_in_bytes 
cgexec-g memory:test mongod-port 27017--bind_ip 127.0.0.1--dbpath/var/ Lib/mongo

After the Cgroup limit is reached, the process is killed when the memory reaches the limit.

[Root@centos mongo]# cgexec-g memory:test mongod-port 27017--bind_ip 127.0.0.1--dbpath/var/lib/mongo 2014-07-18T23: 20:53.228+0800 [Initandlisten] MongoDB starting:pid=2529 port=27017 dbpath=/var/lib/mongo 64-bit host=centos 2014-07-1 8t23:20:53.228+0800 [Initandlisten] db version v2.6.3 2014-07-18t23:20:53.228+0800 [Initandlisten] git version: 255F67A66F9603C59380B2A389E386910BBB52CB 2014-07-18t23:20:53.228+0800 [Initandlisten] Build Info:linux build12.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri 3 21:39:27 UTC 2014 x86_64 boost_lib_version=1_49 2014-07-1 8t23:20:53.228+0800 [Initandlisten] Allocator:tcmalloc 2014-07-18t23:20:53.228+0800 [Initandlisten] Options: {net: {b Indip: "127.0.0.1", port:27017}, storage: {dbpath: "/var/lib/mongo"}} 2014-07-18t23:20:53.304+0800 [Initandlisten] J Ournal dir=/var/lib/mongo/journal 2014-07-18t23:20:53.304+0800 [Initandlisten] recover:no journal files present, no rec Overy needed 2014-07-18t23:20:53.374+0800 [InitandlIsten] Waiting for connections on port 27017 2014-07-18t23:20:57.838+0800 [Initandlisten] connection accepted from 127.0. 0.1:36712 #1 (1 connection now OPEN) 2014-07-18t23:21:15.077+0800 [Initandlisten] connection accepted from 127.0.0.1:3671 3 #2 (2 connections now OPEN) 2014-07-18t23:21:52.342+0800 [conn2] getmore test.my_collection cursorid:34538199491 Ntoret urn:0 keyupdates:0 numyields:39 Locks (micros) r:121572 nreturned:95052 reslen:4194299 202ms 2014-07-18t23:21:53.376+ 0800 [Clientcursormon] Mem (MB) res:136 virt:12809 2014-07-18t23:21:53.376+0800 [Clientcursormon] Mapped (incl Journal VI EW): 12508 2014-07-18t23:21:53.376+0800 [Clientcursormon] Connections:2 2014-07-18t23:21:56.790+0800 [CONN2] Getmore Test.my_collection cursorid:34538199491 ntoreturn:0 keyupdates:0 numyields:88 Locks (micros) r:142113 nreturned:95595
 reslen:4194301 244ms killed

Data Query script:

[Root@centos data]# cat mongotestlist.py 
import pymongo 
import time 
 
client = Pymongo. Mongoclient ("localhost", 27017) 
db = client.test 
print db.name 
print db.my_collection for 

item in Db.my_collection.find (): 
  Print Item

Data Insert Script:

[Root@centos data]# cat mongotest2.py 
import pymongo 
import time 

client = Pymongo. Mongoclient ("localhost", 27017) 
db = client.test 
print db.name 
print db.my_collection while 

True : 
  Db.my_collection.save ({time.ctime (): Time.time ()})

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.