May 06, 2009 22:53
So, I looked at what FreeBSD Jails are and what they can do. I must say, I was quite amazed. It turns out FreeBSD Jails offer the same environment isolation, process isolation, and resource management as virtualization, but without the overhead of virtualization. Jails are so isolated, in fact, that you have to install FreeBSD in the location where the jail will be rooted. Then you have to install the software for it, just like you would for a VM or an actual box. Unlike virtualization, you can use a single FreeBSD installation and, using mountpoint trickery, have the software, configuration, and data for multiple jails separate. Sure, you can have 2 FastCGI-PHP jails and a database jail, the only things that are different are /usr/local, /etc, /usr/home, /var, and /tmp. But the base FreeBSD installation is shared between all the jails, thus minimizing disk space.
So there's two advantages of using FreeBSD Jails over traditional virtualization:
+ Less in-memory overhead
+ Less disk space via mountpoint trickery
And all the benefits of traditional virtualization (via Xen or VMWare):
+ Total isolation
+ Potential for multi-homed host within the VM
So I've been setting up my FastCGI server for FreeBSD Jails. I built and installed the OS for the jails, then I chrooted into the complete jail (with all its mountpoints) and installed (almost) all the software it needs. I'm going to instance two jails using the same root path. So this is like two machines for the disk space of just one installation.
But here's where I find myself with a question I cannot seem to answer by myself. How do I handle the load balancing?
I'm using Cherokee on the web server because its just omginsanelyfast, but it has issues with FastCGI (PHP memory leak from hell). So I make Cherokee act as a reverse proxy and send requests for PHP over to lighttpd, currently running on the same machine (just a different port). Lighttpd then sends its FastCGI requests to the FastCGI server.
The question I face now is this: Do I keep lighttpd on the web server and let it do the load balancing directly with two FastCGI jails, or do I move lighttpd into the jails and let Cherokee do the load balancing?
Either way, the pros and cons have the same weights, and thus, I am unable to make a decision.