is mod_rails or Phusion Passenger finally the answer to Ruby on Rails Deployment? - ruby-on-rails

I read from some books that Phusion Passenger is the answer to easy Ruby on Rails deployment. But my friend said that first there was Apache + bunch of Mongrels, and then lighttpd, and then nginx, and now Passenger, and it seems endless...
he also said he uses dreamhost which uses Passenger, and sometimes he sees his request not being processed.
So I wonder if Passenger is the final answer to RoR deployment? do you use it and used the "ab" command to test if the site is doing quite well?

short answer: yes.
long answer: yeeeeeeeeeeeeeeesssssssssssssssss.
In all seriousness, Phusion Passenger and Ruby Enterprise Edition have taken out pretty much all of the pain of moving a Rails app into production. Previous approaches, including running a suite of Mongrels, required lots of setup surrounding starting, stopping, and recycling listener processes that Passenger handles transparently, or via simple Apache (or nginx) configuration options. And REE's complementary garbage collector means that forking off a new listener uses MUCH less memory, and is faster to boot (in Passenger's "smart" spawning mode).
Edit: #srboisvert makes a very good point; Passenger isn't the final answer to RoR deployment, but for now it's my favorite by far. One day, after a lot of hard engineering problems are solved, mainstream Ruby will probably move from hosting RoR using a multi-process model to a single-process model, which would make management even easier than with Passenger.

It's the best solution so far. I started deploying with FCGI and it was a pain. Then came mongrel and it was better. Then came mod_rails and it was WAY better.
Also a lot of large cool application are migrating to mod_rails including some by 37signals, so you know that's good.
I'll just end with a quote from DHH:
The one-piece solution with Phusion
Passenger
Once you've completed the incredibly
simple installation, you get an Apache
that acts as both web server, load
balancer, application server and
process watcher. You simply drop in
your application and touch
tmp/restart.txt when you want to
bounce it and bam, you're up and
running.
But somehow the message of Passenger
has been a little slow to sink in.
There's already a ton of big sites
running off it. Including Shopify,
MTV, Geni, Yammer, and we'll be moving
over first Ta-da List shortly, then
hopefully the rest of the 37signals
suite quickly thereafter.
So while there are still reasons to
run your own custom multi-tier setup
of manually configured pieces, just
like there are people shying away from
mod_php for their particulars, I think
we've finally settled on a default
answer. Something that doesn't require
you to really think about the first
deployment of your Rails application.
Something that just works out of the
box. Even if that box is a shared
host!
In conclusion, Rails is no longer hard
to deploy. Phusion Passenger has made
it ridiculously easy.
(via)

Yes, it is the easiest, fastest and most efficient solution.
After a lot of problems with gems like soap4r etc. had been resolved in recent releases, Passenger is the answer to deployment questions now.
We're running Apache/mod_rails in a balanced environment with HAProxy in front of 2 servers. It's much more reliable than our previous setup using Mongrel/Aapache.
It's very easy to take control over
the amount of Passenger processes running in Apache
the amount of Passenger processes running per application
and all that without the pain of tweaking a number of config files like mod_proxy, Apache.
setting up a virtual host and adding 3 lines to your Apache config is basically enough to get it running
Matt

Final Answer? Nothing is ever the final answer.
I'd say Passenger is the current answer though.

Yes. I've been running Nginx/Passenger in front of Apache for whatever still needs PHP since they released 2.2.0 a few weeks back. Especially with Ruby Enterprise Edition, it approaches what I would call "perfect".

I guess that now people will stick to mod_rails for many years. The module is really good. Configuration is dead simple. It will be hard to replace it with some better solution. Similar to mod_php. The only key component which is missing: Windows port.

In some situations (enterprise, etc) the JVM can also be a good option.

Related

Making ruby on rails take up less memory

I'm trying to run a Ruby on Rails project (redmine) on a VPS. It's working, but it takes quite a bit of RAM. The rails application has very light usage compared to the rest of the VPS. I have lighttpd running on the server as well.
I'm new to Ruby and know there are several ways to launch a webapp in Ruby. I'm currently just using webrick (and am okay with launching it by hand). Is there another way to launch a webapp that is more memory efficient?
Rails really just takes a shitload of memory, it's a damned big app. One of the things you can do is try to get Ruby Enterprise Edition installed but if you're on a VPS there's probably not much chance of that. But perhaps the best option is to drop the app on heroku and not worry about it anymore. You'll have other difficulties like setting up email to contend with but otherwise Heroku is the best thing that ever happened to rails (I think at least. Maybe Merb though :P)
If you're new to Rails, configurations, and even Linux - your best bet is Apache/Nginx + Phusion Passenger + REE. If your VPS is something you control such as Slicehost, Webbynode, Linode, or similar - then that'll be the easier route.
Slicehost articles should help you out a lot by walking you through each step of configuring your VPS. And the steps even work on other VPS hosting companies, just match up the Linux distro.
If you're really green to RoR and setting up VPSes's-es (?) and unless you need more than a 512MB slice - I agree with Chuck, start with Heroku until you hit about 3-4 dynos. And since the Redmine demo is on Heroku - you know it works!

Recommendations for a snappy Ubuntu + Rails server

I run an Ubuntu 8.04 shared host (VMWare) with Apache + Passenger (= Mod Rails), MySQL and Acts_As_Ferret (in server mode). It's too slow at the first requests. I do a lot of REST operations on it and have very few users.
Now I want to do a fresh installation...
Which setup (based on Ubuntu) do you recommend for a really snappy RoR server? (e.g. Ngnix, Thin, Mongrels or other fancy stuff)
Passenger is slow at first requests because it is idling and it shuts down all the rails processes so the first request has to load a rails process. You need to either ping regularly to avoid it idling and closing rails processes or set the idle timeout to a high value.
Look in the documentation for RailsPoolIdleTime
Check the ec2onrails mailing list, where there has been a lot of discussion of the various thin/nginx/passenger/apache alternatives and permutations, plus some hard data posted based on some decent tests.
You'll also find a nice packaged RoR/Ubuntu stack in the shape of the ec2onrails image (google ec2onrails) - it's for running on the amazon EC2 cloud but it's got a lot of nice stuff in there + capistrano tasks. Currently it's based on apache, but the version in progress is looking at the alternatives. No reason you couldn't use the same build script for a non EC2 server.
If your problem is simply the initial requests, try warming your server up before considering it live (e.g. by running a script to automatically exercise the basic operations).
Oh and I should add - are you sure the problem is your stack? More likely it is your code. It may be worth seeing where your bottlenecks are first and what you can get out of caching, improved queries and indexing, and especially memcached before tweaking anything else.
Well you could get a big speed boost by switching to Ubuntu 9.04 or even 8.10
I personally use nginx+passenger on my ubuntu stack. and use sphinx instead of ferret as well

Recommendations (and Differences) between different Ruby on Rails Production Web Servers

Very soon I plan on deploying my first Ruby on Rails application to a production environment and I've even picked a webhost with all the managed server and Capistrano goodness you'd expect from a RoR provider.
The provider allows for Mongrel, Thin, Passenger & FastCGI web servers, which seems very flexible, but I honestly don't know the differences between them. I have looked into them some, but it all gets a bit much when they start talking about features and maximum simultaneous requests - and that this data seems to vary depending on who's publishing it.
I have looked at Passenger (on the surface) - which does seem very appealing to me - but I was under the impression that Passenger wasn't the actual webserver, and instead was more like a layer on top of Apache or nginx and managed spawned instances of the application (like a Mongrel cluster).
Can anyone please set me straight with the differences in layman's terms so as I can choose wisely (because anyone who's seen Indiana Jones and the Last Crusade knows what happens if you choose poorly).
Short answer
Go with Apache/Nginx + Passenger. Passenger is fast, reliable, easy to configure and deploy. Passenger has been adopted by a large number of big Rails applications, including Shopify.
(source: modrails.com)
The long answer
Forget about CGI and FastCGI. In the beginning there were no other alternatives so the only way to run Rails was using CGI or the faster browser FastCGI. Nowadays almost nobody runs Rails under CGI. The latest Rails versions no longer provides .cgi and .fcgi runners.
Mongrel has been a largely adopted solution, the best replacement for CGI and FCGI. Many sites still use Mongrel and Mongrel cluster, however Mongrel project is almost dead and many projects already moved to other solutions (mostly Passenger).
Also, a Mongrel based architecture is quite hard to configure because it needs a frontend proxy (thin, ngnix) and a backend architecture composed of multiple Mongrel instances.
Passenger has been gaining widespread attention since it was released. Many projects switched from Mongrel to Passenger for many reasons, including (but not limited to) easy deployment, maintainability and performance. Additionally, Passenger is now available for both Apache and Ngnix.
The simplest way to use Passenger is the Apache + Passenger configuration. One Apache installation and multiple Passenger processes.
If you need better performance and scalability, you can use Ngnix as a frontend proxy and forward all Rails requests to multiple backend servers, each one composed of Apache + Passenger.
I'm not going into the technical details here, this solution is intended to be used by Rails projects with an high level of traffic.
Even more complex solutions include a combination of different levels including http proxies and servers. You can have an idea of what I'm talking about reading some internal details from GitHub and Heroku.
Right now, Passenger is the best answer for most Rails projects.
Mongrel and Thin are single ruby process servers that you would run multiple of as a cluster behind some type of proxy (like Apache or Nginx). The proxy would manage which instance of Mongrel or Thin services the requests.
Passenger creates an interface between Apache or Nginx that creates an application spawning process and then forks out processes to server up incoming requests as they come in. There are a lot of configuration options for how long those processes live, how many there can be, and how many requests they will serve before they die. This is by far the most common way to scale up and handle a high traffic application, but it is not without drawbacks. This can only be done on a *nix operating system (linux, mac os x, etc). Also, these processes spin up on demand, so if no one accesses your site for a while, they processes die and the next request has the delay of it starting back up again. With Mongrel and Thin, the process is always running. Sometimes though, your processes being new and fresh can be a good thing for memory usage etc.
If it is going to be a relatively low traffic site, Mongrel or Thin provides a simple, easy to manage way to deploy the application. For higher traffic sites where you need the smart queuing and process management of something like Passenger, it is a very good solution.
As for fastcgi, you probably want to use that as a last option.
I use Passenger + nginx. It works really, really well.
To get some instant performance boast with passenger, I recommend using ruby enterprise edition.

Should I user Apache or Nginx & Passenger or Mongrel for my Rails application

I have a Ruby on Rails application that will be a CMS in way which means it's mostly DB intensive. I expect it to have decent amount of traffic so before designing I'm choosing what servers to use. Most important for me is performance.
I heard good things about Nginx and many developers in the Rails community recommends it my only concern about it was that its version is 0.8 which is Beta I believe so I was concerned about potential problems. What is your say?
Also, I want to decide between using Mongrel cluster or Phusion Passenger. What do you think?
I'm planning to user Ruby 1.9 as it has better performance that Ruby 1.8 and I will be using VPS to host my website.
My main things is performance even if it takes longer to setup one over the other.
Your opinion is highly appreciated.
Thanks,
Tam
I'd second for Passenger + Nginx. Very low memory and it's not too difficult to setup. What type of server are your deploying too? Specs? OS? I'd take that into consideration as well considering your available hardware. If you've got enough memory already, then it shouldn't be an issue whether its Passenger or Apache, just optimize and cache your app efficiently.
Two comments:
You can deploy any rails app to any of your mentioned servers, so no need to decide this once and for all now.
IMO mongrel clusters are no longer worth the trouble. Go for passenger on whatever server makes you happy.
Id recommend passenger nginx, the configs are nice and tidy plus the memory footprint is really low compared to passenger apache.

Ruby on Rails running on a vps slice

What are the major gotchas and tricks when running Rails on a small slice (256MB)? What is the best server setup for cramped quarters? Passenger, Nginx, Mongrel? What is the best background task processor in this kind of environment? What do you need to watch out for? I'd love to hear the stories of people who have done this and bumped into some of the virtual walls.
I'm running Passenger on a 256mb slicehost, no problems. Much, much, much easier to set up than any other alternative. For background stuff I use Starling and Workling and Ryan Bates has an excellent screencast on how to use both together.
Nginx proxying for a couple of mongrels. Updating gems can cause you to run out of memory, but this can be solved by downloading and compiling rubygems from source. You will have no problem using cron for background tasks as it is very lightweight.
On my 256 slice I run nginx in front of a pair of thin servers. Whatever you decide to go with make sure you're using god or monit to keep your stack in check.
I suggest Passenger for it's simplicity and smallish footprint. I have that on my VPS with several domains (256MB VPS on RailsPlayground) and no problems so far. Also, the Starling/Workling combination works pretty well or you could even just use the spawn plugin if your site isn't huge (it's dead simple).

Resources