Disclaimer: This is just a stream o thoughts I have been wanting to get out of my chest for some time. I have published some stuff in Czech (my native language) and I feel like putting something down in english. I am not sure there will be a conclusion but I will do everything to stay with facts and leave personal stuff and feelings out.
In the past I had some experience with Ruby On Rails on shared hosting and recently I have tried virtual server hosting and ultimately moved to my own dedicated mashine placed in a housing center. This said I think it is safe to say I have at least some overview of what issues people on shared hosts face every day and due to close cooperation with my hosting provider and also my own admin experience I also have some experience of what issues hosting providers/administrators face when setting up environment for their clients.
Right now there are multiple Rails deployment models. I will not go though each and every one separately, but I think they can be easily categorized into two groups. Sice Ruby is an interpreted language you need an instance of the interpreter running for your app to work. Since the classic Ruby interpreter is not in blazing speed it is good to load up the interpreter cache up the code in memory and then execute it. The question is "Who starts those instances?" and this is how I categorize Rails deployment models:
- Instances of interpreter are started by the webserver (apache)
- Instances are started externaly and independently on webserver
If you have any experience with Rails deployment you will agree with me that nowadays the only viable option is number two. You want your code to be cached and serve several requests before being reloaded. And when updating your application you canot restart the whole webserver which is propaby serving dozens of other sites. So what now?
This is mainly the issue of shared hostings. It is simply unacceptable to allow your users interfeere with the front end webserver (option number one is out). But allowing users to start some back-end processes is also risky because controlling who uses which port is really not easy. Still no conclusion.
When I started setting up my own production server I first reached out to FastCGI (more accurately mod_fcgid for apache) and I was really supprised by the performance. The application just felt blazinly fast. The headaches came when setting up multiple application deploying with Capistrano. Each deploy caused restart of Apache. Which is not pretty. I started looking for alternatives.
Then I gazed on
SwitchPipe. A project I read about some time ago but completely forgot it (since it was no good for me at shared host). I actually think SwtichPipe-like kind of thing might be the ultimate answear to Rails deployment.
Rails is single threaded so a situation similar to Java/Tomcat stack when several Java threads are serving requests from Apache is not applicable. What Threads to in Tomcat, Mongrel (or any other Rails container) has to do with multiple instances. Again there are several options how to archieve this. For example
this tutorial describes rather througly how to setup apache to proxy requests to your local Mongrel instances. Its a cool tutorial but when I saw all the configuration needed my head started to spin. This not Rails-like at all. No way I am gona do this.
The great thing about SwitchPipe is that all the configuration (even if you want to change almost everything) is about 10 lines max for a signle Rails/Mongrel application.
For Apache to use your SwitchPipe cluster you need to do the follwing in your .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://127.0.0.1:10000/myapp/$1 [P]
All the lengthy stuff Rails generates for you can go away. It is pretty lovable. Now the actual SwitchPipe config for your site:
path: /path/to/your/app
type: mongrel_rails
max_instances: 2 # whatever you want
timeout: 30
user: yourUserName
# this is good for shared hosts, apps run with permissions of actual users
# files get created right and users can work with them
I might be short sightet. I sure do not know all the issues faced by the hosting providers/clients but this kind of setup is pretty easy to automatize. Restarts of the cluster are curently handled by touching the SwitchPipe configuration file, but this is promised to get improved (I myself am hoping to try and create the patch).
Still, Rails deployment is far different from what the PHP folks are used to. Rails is just different. So what? Get used to it or dont use it! Yes, for me it is that simple. After my recent experience with setting up multiple virtual-host webserver I have came to conclusion that the
Rails Deployment problem is just a FUD, nothing else. You know Java, right? You know .NET right? There are not plenty of hostings for applications like this. I say they have a deployment problem, not Rails. Whether you are setting up your own (virtual)server or shared hosting environment for your users, learn something about Rails and Ruby and Mongrel, check out SwitchPipe and enjoy. Rails world is really fun.