Sunday, March 20, 2011

Scaling myVidster Part 3: Apache + PHP-FPM

Recently I decided to upgrade my servers so that myVidster can keep up with its growing traffic. I also decided to implement PHP-FPM to fix an issue with my APC setup discussed in Scaling myVidster Part 2.

Before the upgrade my setup was Apache +  MOD_FASTCGI + APC.  I did not have any issues with server performance but the APC host would restart every 2 hours.  This concern me because the cache would have to warm back up (rebuild) and during high traffic this could cause a bottle neck.  With that in mind I decided to add PHP-FPM to my setup.

I follow the setup instructions posted here and got PHP-FPM setup with only a few headaches.  My biggest learning was recompiling MOD_FASTCGI.  His steps are for a DSO install and I decided to go with a static library instead because I have done it before and was succesful.  After I recompiled PHP with PHP-FPM, I tried to use my old static library copy of MOD_FASTCGI which caused my server to fail.  To solve this I had to recompile the static library.

Also the default settings in the php-fpm.conf could not handle the traffic.  For those who use PHP-FPM here are my settings.

pm.max_children = 225
pm.start_servers = 60
pm.min_spare_servers = 40
pm.max_spare_servers = 80
pm.max_requests = 500

I am still getting the '[pool www] seems busy' warnings once in a while, so I might increase these values.

My new setup is Apache +  MOD_FASTCGI + PHP-FPM + APC and have been running this setup for the past 2 days.  My first impression is that I love this setup!  PHP-FPM gives you more control on how your server executes php scripts and the APC host no longer restarts every 2 hours.  As for performance I did not execute any benchmarks but I did notice faster and more responsive page loading.  I will also like to note that the Apache + PHP-FPM setup is not too common and most people use Nginx instead.  Right now no one has published any benchmark data comparing the two setups.  So for now go for what works for you and your visitors!

No comments: