Mounting a MySQL database from a ram drive in slackware

2008-12-27 21:49 by Ian

This might help anyone out there building embedded devices running linux. It is an example of how I maximize performance while minimizing database latency and flash memory wear by keeping high-IO traffic files on a RAM drive while they are in use.

In my car’s computer, I have a MySQL database that handles basically all of the information interchange between various parts of the software environment. When the back-end needs to communicate with the user or the remote server, it writes records to the database. The user interface does the same thing. These

Because of the fact that the main hard drive in the computer is a compact flash card (max write speed: ~400KB/sec), the latency of this database was strongly tied to the performance metrics of the CF card on the IDE bus. For an application that strives for 20ms response-time in most of the UI, this is a serious problem.

The solution I came upon was to create a RAM disk and copy the MySQL data files into it before starting the MySQL daemon. I do that first by specifying (in /etc/lilo.conf) how large I want my RAM drive to be. I chose 128MB…

After re-installing LILO, I edit the run-level 3 startup script. In this script, I put the commands to mount the RAM drive, create a file system, copy the data files, and set the permissions. When the system starts MySQL, the DB is completely disentangled from the compact flash card.

But if any of our changes are going to remain intact between reboots, we have to place something like this in the rc.6 script…

This will stop MySQL (if it isn’t already), and copy the contents of the RAM drive back to the CF card for more permanent storage.

The net result is a blazing fast DB, decreased stress on the flash memory (which may be running at ambient temperatures as high as 160 degrees F), and lower user interface latency.

The biggest cost is the risk of data loss and the size constraint placed on the DB by virtue of its location in main system memory.

Previous:
Next: