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?
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
I'd be inclined to think that if you've got a machine with enough RAM, the OS disk cache will do just as well at caching the appropriate content (if not better, because it won't cache files that aren't used), but you should benchmark it on a test server, after verifying that you are, in fact, hitting disk excessively (with sar).
The biggest hog of PHP is, for every request the interpreter has to
With APC you can skip all steps and jump straight to execution. If you have performance issues, and especially after having observed the profiling results you mention, do install and configure APC. You will be astonished what performance gains you get.
I faced the problem of optimizing a large set of wikis for the Howtopedia organization; after press releases, the newspaper coverage they'd get was systematically taking system load to 100%. Configuring APC with just 25 MB of cache brought system load straight to less than 5%. Some further basic tuning to less than 1%.
At the same time, since most of what steps 1-3 do is introduce latency, the response time experienced by users improved dramatically.
Some further tips for the scenario you describe:
No, it won't if RAM is already the bottleneck.