Posts Tagged ‘ram’

Post

Running MongoDB Completely in RAM

In sysadmin on August 11, 2011 by Wenzi Tagged: , ,

The project I am working on runs test cases constantly ( and you should too ) that are constantly creating and destroying MongooDB databases.

All those database allocations ( Mongo allocating the datafile ) was taking a lot of time on this not small project.

So with a need for speed, we put the database in RAM. This is how, if you need more speed , you can run Mongo completely in RAM.

/home/me# mkfs -q /dev/ram1 32768
/home/me# mkdir -p /ramcache
/home/me# mount /dev/ram1 /ramcache

[1] Make a filesystem in ram. mkfs makes a /dev in ram of the specified size. In this case 32M ( 32768 ), but you will have to make a bigger one for mongo, greater than 192M.

[2] Make a mount point. We need a directory to ‘attach’ the ram filesystyem so normal applications can access it as part of the file system.

[3] Mount the drive. Mount the ram drive on the mount point you just made.

To test it, we run mongodb with the ramcach as the datapath.

mongod –dbpath /ramcache/ –port 29019

 

Looking at the directory from another terminal window ( or tmux ) we can see that the lock file was created.

me@li132-23:~$ ls -la /ramcache/
total 18
drwxrwxrwx 3 root root 1024 Aug 11 04:36 .
drwxr-xr-x 22 root root 4096 Aug 11 04:31 ..
drwx------ 2 root root 12288 Aug 11 04:30 lost+found
-rwxr-xr-x 1 me me 6 Aug 11 04:37 mongod.lock

Now we can connect to the mongo server.

mongo --host localhost:29019

Now it just acts like a regular server, because it is, just running in RAM.

> use wenzi
switched to db wenzi
> doc = { author : 'wenzi', post : 'Water : the new Coke' }
> db.posts.insert(doc);

Comments Off