I am currently in the process of switching everything over to a new server. This is the first post on the new server. It's quite a bit faster than the old one. I have been planning to write about the steps I took to get everything switched over. Those posts should happen sometime in the near future.
Tags: site
Categories: Server
Date: 04/22/11
A few months ago I decided to re-configure the server that run's this site and some friends sites. I had heard nice things about nginx and how it is really fast as a front-end for apache. In the process I heard about running apache in MPM-Worker mode. The difference between that and Prefork is that in worker mode Apache doesn't need to spawn more processes when more people start visiting the site, everything is handled in threads. You can save a good chunk of memory by using Apache in Worker mode. There is a downside however, all the modules that Apache is running must be thread safe. As far as I can tell the version of PHP that comes in most linux distro's is not thread safe, well it might be but some external libraries php uses aren't. So currently it seems as though running a thread safe version of php is pretty low, you could compile it yourself but packages are easier and cleaner to upgrade.
So I decided to run Apache in Worker mode and run php using fastcgi via mod_fcgid. On top of that nginx is sitting on the front-end serving up static content and when needed caching data. After setting everything up things were running faster, yet there was still a downside. I use opcode caching for PHP as it allows me to squeeze more out of my server. Now when running php via mod_fcgid having php spawn children is not a good idea as they aren't managed by fcgid and no requests are sent to them. Instead of having a parent php process and a bunch of children sharing opcode caches you have a bunch of parent php processes each with their own opcode caches. The biggest downside comes when you want to invalidate data in the caches, since each process has it's own cache if you invalidate something is is only invalidated in one cache.
This lead me back to using Apache2 in Prefork, since apache spawns children they all share the same PHP opcode cache. Since I have nginx sitting in front of apache serving up static content I am able to get great performance on static stuff. Now apache only gets hit when serving stuff like PHP.
After switching Apache back to Prefork I've actually seen higher performance out of Feedstock than I did before. The memory usage is about the same as before so its not like I lost out by switching back. The bonus is also that there is one opcode cache for PHP that all the Apache children can share.
So I decided to run Apache in Worker mode and run php using fastcgi via mod_fcgid. On top of that nginx is sitting on the front-end serving up static content and when needed caching data. After setting everything up things were running faster, yet there was still a downside. I use opcode caching for PHP as it allows me to squeeze more out of my server. Now when running php via mod_fcgid having php spawn children is not a good idea as they aren't managed by fcgid and no requests are sent to them. Instead of having a parent php process and a bunch of children sharing opcode caches you have a bunch of parent php processes each with their own opcode caches. The biggest downside comes when you want to invalidate data in the caches, since each process has it's own cache if you invalidate something is is only invalidated in one cache.
This lead me back to using Apache2 in Prefork, since apache spawns children they all share the same PHP opcode cache. Since I have nginx sitting in front of apache serving up static content I am able to get great performance on static stuff. Now apache only gets hit when serving stuff like PHP.
After switching Apache back to Prefork I've actually seen higher performance out of Feedstock than I did before. The memory usage is about the same as before so its not like I lost out by switching back. The bonus is also that there is one opcode cache for PHP that all the Apache children can share.
Categories: Server
Date: 05/05/10