3

I'd like to store the content on my VPS in RAM as apposed to using the disk. Is there any way I can do this using Apache and PHP? I want to do this to minimise the time it takes to retrieve the content.

Also, is storing in RAM typically faster than storing on an SSD?

Francis
  • 33
  • 3
  • Have you considered solving this at OS level: http://en.wikipedia.org/wiki/RAM_drive ? And yes, RAM is much faster than SSD, but you have a risk of loosing data, so you can probably keep only read-only stuff in the RAM FS. – Alin Purcaru Dec 14 '14 at 13:06
  • Can you please detail more what kind of content are you talking about? Is it read only? Is it's not, is it acceptable for newly created content to be available in the RAM with a delay? Can you tolerate lost content? etc. – Alin Purcaru Dec 14 '14 at 13:17

1 Answers1

1

I'm no expert on this topic, but here's what I would try as a basic approach:

I'd keep my application code (including resources like CSS, JS, etc. - to keep it simple) in a location on the HDD. I'd have a RAM mount like:

vi /etc/fstab
tmpfs       /mnt/ramdisk tmpfs   nodev,nosuid,noexec,nodiratime,size=1024M   0 0

and on system startup I'd copy from the HDD over to the RAM mount. Then I'd have the HTTP server (apache) point to the RAM mount, also everything inside of PHP will load code from the RAM mount, not the original location (for the purpose of rutime, the HDD source location does not exist).

For actual content I'd use an in-memory DB. If the content is media-rich some RAM cache like varnish can be used for that part.

There are of course variation to this strategy, or maybe even better solutions, but this also depends on your particular conditions, and you haven't said too much about those.

Alin Purcaru
  • 43,655
  • 12
  • 77
  • 90