Ok so let’s talk about what I have, and how it’s all configured:
- Varnish Cache
- Nginx Web Server
- PHP-FPM (plus MySQL)
- Physical Server / Data Center
Varnish Cache
Traffic to my sites can get quite intense some times and it’s important to keep things going when it does, in some cases I have had 10,000 unique visitors come to a website within an hour or two, visitors bring revenue so it’s important to service every request.
My previous setup fell over the first time this happened so I needed to change some things including the server and configuration. The server I have has more RAM than I need, so I use Varnish to sit infront of my websites and cache their static content in memory.
This means my web server can concentrate on processing php dynamic page requests, while returning images/css/files is managed by varnish. Also the home pages and highly viewed content can be complete cached to ensure that doesn’t go anywhere near the web server.
Varnish is great for this, it keeps the disk IO very low and the server load even lower. In normal operation there probably isn’t a great deal of benefit however it’s invaluable when the websites get loaded. I highly recommend using it if you have 0.5 to 1.5GB~ of free memory on your web server.
Nginx Web Server
Apache is great and works for most people, however most people don’t use 99% of it’s features. Nginx is like it’s much slimmer and faster brother that does almost everything apache does, plus a few extra things. By using Nginx I get a faster web server and save physical resources, so they can be used for things such as Varnish. Also the web server is very easy to configure and just works great!
PHP-FPM (plus MySQL)
This is where all the magic happens, all of my projects have some PHP in them as it’s really the language that I am most experienced in, even this blog that I didn’t write (yeh it’s just wordpress) is in PHP.
Most people build php into their apache install, however I don’t have apache, so I just Nginx to reverse proxy all the .php requests back to php-fpm on the same server. Each user gets their own process for each of their requests and it’s served back to them very fast. This was one of my biggest advantages with one of my recent projects where PHP took about ten seconds to render the page, I could spawn 40+ processes to ensure every user was getting their page as requested.
In the past I used MySQL with a minimal configuration, because my VPS’s were fairly memory bound they didn’t cache much information, instead they were constantly using the disk i/o. However I am now in a different boat, the disk in this server isn’t that great however I have quite a bit of memory free. My data sets are fairly small, in fact most of my sites and projects are under 10MB if you remove my quite verbose configured logging, thats including the scripts and supporting database information required for operation. MySQL is therefore now configured to cache most of it’s content in memory, disk is slow, memory is fast and plentiful!
Physical Server
Here is some basic information on my server from OVH:
- Intel(R) Atom(TM) CPU D425 @ 1.80GHz
- 4GB of RAM
- 2TB HDD
- 100Mbps port
- Located in USA (OVH)
- IPv4 and IPv6 connectivity
- 100GB of free backup space
- Debian 64bit