Drupal on Nginx - Static File Performance
Recently I've tried running Drupal on nginx to boost performance. Instead of using nginx as a proxy to apache to run php, I use fcgi called by nginx. Of course the static files are served directly by nginx with nothing to get in the way.
To get an idea of how far I could push the server I ran a few tests. Since most of the files requested for a page are static files and I've mostly focused on optimizing Drupal itself so far, I wanted to see how fast it could serve the static files. The configuration was:
Webserver:
- 4 CPU cores (this is on Rackspace cloud, and the server reports an Opteron 2374 HE)
- 16GB RAM
- Only running nginx and fcgi
- Located in Texas
Load test:
- Single server running ab on Peer1
- 10-250 concurrent connections
- 5000-20000 requests per test
- Requesting a 1.34KB image file
- Located in Virgina
Results:
- With some tuning of the concurrent connections, the load testing server was able to fetch the image 5500-5700 times per second.
- In all my testing, the web server showed a peak load average of 1.2 (using just over a quarter of the CPU power)
- The memory usage on the webserver stayed around 400-600MB
- I tried running other small tests from different sources at the same time and they didn't reduce the performance
This test shows that nginx on a single server with good resources can handle very high loads when serving static files. With requests coming from many sources it should have even better performance. Based on the internal resource limitations, it seems like the server could handle a sustained load of at least 18,000 static files per second without any trouble and possibly much more. If each page used 20 static files, that would be enough to populate 3.2M pages per hour. Of course as the size of the files increases it may have a slight effect on the server load and run into bandwidth limitations.
In the past I've always used configurations that had Apache doing everything so this will change the performance options. In real-world usage, the cost of serving static files will be a lot less noticeable compared to the resources used by Drupal. In this case it may be a while before the website traffic catches up to the server capacity!