PHP Fast Process Manager
The design of Acorn and Mangler was aiming for light-weight and blisteringly fast — however, eventually you become limited by the tools that you're using. A good example of this is the standard LAMP stack that is1 ubiquitous in both smaller, and larger3 web environments.
mod_php, the Apache HTTPD module that runs PHP works on a per-request basis; whenever a file has to be interpreted, a new process is created to process it, the interprator is loaded, and only then does the work begin. Adding this start up time to every page is, in the content of this blog, a noticeable overhead.
However, with the arrival of version 5.3.34, PHP-FPM5 was bundled with the main PHP release. The keeps running, at all times, a number of PHP processes waiting for input, essentially removing the overhead for starting them up. Moreover, these processes are reusable, so that overhead is not merely offset, but essentially removed. When first implementing this on my development machine, I saw an average of 30ms coming off the round trip time — which was only at 90ms to start with.
And on the live machine, there are pages which are responding in times close to 20ms. This took some more optimisations — including some work on the database side which I will leave for another post — but was mainly done by working to reduce the number of processes and other system-like things are created.
Another advantage comes out of this — with the removal of mod_php, this machine's Apache configuration becomes thread safe, which allows a major change in it's working model. The default mod_php set up has Apache creating a number of processes, which handle requests. What's more is that a new process has to be created for every active connection and, with Keep-Alive enabled, those collections can each linger for a long period of time. This method, called MPM-Prefork6 has been considered ungainly by Apache for a very long time.
The are a couple of options for what replaces it, but with Event still being experimental7 I have chosen to use the Worker module8 which mixes processes and threads to improve throughput. This then interfaces with PHP-FPM9 using mod_fcgi, sending the information for each request through a socket to be processed.
The configuration detail, and some of the issues, will follow in later posts!
- 1 ↑ Well, at the very least was, however newer technologies are beginning to gain some ground2.
- 2 ↑ However, these include Ruby on Rails, so I'm not 100% sure I approve.
- 3 ↑ Such as Facebook
- 4 ↑ http://www.php.net/archive/2010.php#id2010-07-22-2
- 5 ↑ http://php-fpm.org
- 6 ↑ http://httpd.apache.org/docs/2.2/mod/prefork.html
- 7 ↑ http://httpd.apache.org/docs/2.2/mod/event.html
- 8 ↑ http://httpd.apache.org/docs/2.2/mod/worker.html
- 9 ↑ /post/php-fpm