Linux – Would a PHP application benefit from being served from a RAM drive

disk-cachelinuxramdisk

I am in charge of hosting a PHP application that is large and slow, but easy to scale. The application is entirely static, with writable disk storage needed. We've profiled the application, and the main bottleneck appears to come from loading the application and not the work the application does. The application is not CPU-intensive, although it does use a fair amount of memory (think Magento).

Currently we distribute it by having a series of servers with the same PHP files on their hard drive and a load balancer in front of them. Easy but expensive.

I've been reading about RAM disks and the IO benefits they offer, and was wondering if they would be well-suited to PHP applications.

Since PHP applications are loaded from disk for every request and often involve lots of different files (as opposed to being kept in memory like with a Java application), I would figure that disk performance can be a severe bottleneck.

Would placing the PHP files on a RAM disk and using the mount point as Apache's document root offer performance benefits? A startup script could create the RAM drive and then copy the files (which are plain-text and small) from a permanent location to the temporary RAM drive.

Does this make sense, or should I just trust the linux kernel to cache the appropriate files in memory by itself?

Best Answer

No, a ramdisk would actually hurt PHP (when combined with better solutions such as a PHP accelerator).

The best way to improve PHP performance is to use a PHP accelerator. These are modules that plug into the web engine (apache httpd for example) and cache the compiled bytecode of PHP scripts. This cache is then stored in ram. The result is that future calls to the PHP script don't go to disk at all, the pre-compiled byte code is pulled from the cache. Meaning that you don't gain anything from using a ramdisk, and instead end up consuming ram that could be used elsewhere.

Depending on your distro and which web server engine your'e using, it's likely you already have a PHP accelerator running.

.

Here's 2 good wikipedia articles on the subject:
PHP accelerator
List of PHP accelerators