What is a Ram Disk you ask? Simply put, you carve out a piece of your system’s RAM and use it as a normal file system. But you probably have some more questions…
Why would I want to do this?
Simply put, RAM is very fast. Faster than most (any?) SSD drive. So if you have an application that would benefit from being able to access data very quickly, a RAM disk makes a lot of sense.
That’s amazing… why don’t I just load everything into a RAM disk all the time?
Two primary reasons… First… RAM is expensive and therefore quite scarce compared with conventional hard drive space. So your system probably has a fairly limited amount to work with. Second, and perhaps more critical, RAM is erased whenever power is lost. So if you do a system reboot, or lose power, everything stored on your RAM disk, even the RAM disk itself, is completely lost.
Oi’ that’s bad… when exactly would I want to use a RAM disk then?
Some applications, like MySQL for example, write “temporary” files to disk. These are usually pretty small files that are built on the fly for normal operations. Think of them like a scratch-pad you would use when doing a long equation in Algebra class. These files are built on the fly to store some temporary data (perhaps a specific view of the database as requested by a website page). Often they are used for “cache” as well, i.e. rather than taking the CPU through the task of building as special table from existing tables again and again, it caches the special table so it can serve it the next time it is requested.
Ultimately, if your system gets rebooted, you really don’t care if you lose this kind of data. Furthermore, having this kind of data written to and pulled from a RAM disk, could really improve application performance depending on your use case.
In this article, I am going to talk about building a RAM disk on the fly, and telling MySQL to use it. Furthermore, we are going to create a few scripts to make sure our RAM disk is created at every boot so that MySQL can consistently take advantage of it.
(more…)