views:

41

answers:

3

I have plenty of RAM on my development machine.

Can I move my Rails' application sources to the tmpfs partition in order to gain performance boost because of in-memory storage which is order of magnitude faster than HDD?

I understand that tmpfs is temporary storage by its nature BUT can I use it for this task if I'll write some script to move sources from HDD partition to tmpfs and backup it back to HDD before reboot?

Is it sane?

+1  A: 

Yes, as long as you don't mind losing the data if your machine reboots unexpectedly (e.g. power loss). I don't know what your use case is, but there are cases where the need for performance exceeds the need for securely saving every data persistently e.g. if you don't mind a few hours' worth of data loss). If your use case falls into that category, then tmpfs is a perfectly fine solution.

Lie Ryan
Thanks! I'll give it a try then
+1  A: 

It is sane to use a RAMdisk to speed up access to read only resources.

It is quite dangerous to use this approach for wriable resources because if you lose power during operation you are guaranteed to lose the data. If you don't mind losing data or you implement some form of cache mechanism so that data "saved" to the RAMdisk is copied back to hard disk pretty soon after it is written, then this approach is ok with read/write data.

However, check out the hardware and OS you're running under as well. If you have SSD disks or disks and I/O subsystems with large caches, you may find that performance isn't that bad in the first place. On the OS front, (for example) Windows Vista & 7 will use any spare RAM for disk caching, and this works very effectively, which means you will see little or no performance gain using a RAMdisk.

A RAM disk or cache also only works if you have enough RAM. If there isn't enough RAM in your PC, you'll end up using VM and performance will get worse, not better.

You can quickly try doing this manually to see what sort of performance change you achieve, and then make up your mind if the gain is worth the pain (of copying data from/to the HDD and the extra risks involved).

Jason Williams
+1  A: 

You can use it this way, but it doesn't make much sense:

If you have enough RAM, then the files will be in the filesystem cache (i.e. in RAM) anyway. So, you don't win anything by using tmpfs, but you also don't lose anything.

If you don't have enough RAM, the tmpfs will be flushed out to swap. Now, your Rails sources eat up precious swap space despite the fact there is already a copy on disk in the filesystem. So, you lose swap space and you don't win anything on performance (whether the files are read back in from swap or the filesystem is equally expensive).

If you don't want to take that first time hit until all the files are in the cache, you could put something like this in your development environment startup scripts:

find /usr/lib/ruby/gems/1.9.1/{rails,action,active}* -exec cat '{}' + > /dev/null

Which will read all the Rails files and echo them into /dev/null and as a side effect pull them into the cache. (Do this while getting your coding coffee.)

Jörg W Mittag