RAMDISK

RAMDISK is part of system memory which user can use as a normal disk space. The advantage of RAMDISK is faster read and write access in comparison of Hard Disk.

By default Ubuntu mounts RAMDISK on /dev/shm/ directory.

To setup RAMDISK on other distributions like Fedora or CentOS, you can follow below method. My machine’s actual RAM size is 4GB out of which I am going to use 1024MB for ramdisk.

NOTE: You can also use below method on Ubuntu.

# mkdir -p /media/ramdisk
# mount -t tmpfs -o size=1024M tmpfs /media/ramdisk/

This is a useful technique for writes from mysql as an example:

root@test [~]# mkdir /tmp/mysql-tmp/
Get the user id and group id of MySQL:
root@test [~]# id mysql
uid=101(mysql) gid=103(mysql) groups=103(mysql)
Change permissions of the directory:
chown 101.103 /tmp/mysql-tmp/
Now we edit /etc/fstab and add the following line (replace UID and GID):
tmpfs /tmp/mysql-tmp/ tmpfs rw,uid=UID_HERE,gid=GID_HERE,size=2G,nr_inodes=200k,mode=0700 0 0
This will create a 2 GB RAM-Disk which MySQL has full access to read/write to.
To mount the disk:
mount /tmp/mysql-tmp/
Now you can edit /etc/my.cnf to point to the new RAM-Disk directory:
[mysqld]
tmpdir = /tmp/mysql-tmp/
Now give MySQL a reboot and confirm that the tmpdir for MySQL is set correctly:
root@test [~]# /etc/init.d/mysql restart
Shutting down MySQL… [ OK ]
Starting MySQL. [ OK ]
root@test [~]# mysql -e “show variables” | grep tmpdir
tmpdir /tmp/mysql-tmp/

This can speed up web application but obviously making sure that you have enough memory for other services needs to be looked into first but this is an effective to help your application run smoothly. It is important to Keep in mind once you reboot, the contents of the RAM-Disk will be gone. So do not use it as storage space, but only as temporary space.

This entry was posted in Managed Hosting. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>