Twitter switches from Mongrel to Unicorn
engineering.twitter.com
engineering.twitter.com
I wish they had discussed why unicorn instead of mongrel and why didn't solutions like haproxy or passenger or ... didn't work?
This discussion was: our apache configuration didn't work so we switched the load proxy mechanics and our app server at the same time.
I've had great success with mongrels with HAProxy (with maxconns=1 so only 1 request per mongrel at a time) for years. I've also had great success at Passenger with apache.
I think it is a great step forward for twitter's servers, I just wish the article had some meat. Isn't this the twitter engineer blog, not blog for the general audience about how twitter works?
But in the edge case of immense load, they simply don't keep up to Unicorn.
The thing that sets Unicorn apart is that it does it's load balancing on the Kernel level. All Unicorn worker processes are listening on the same socket. The OS takes care of getting each request to a single, available worker. So unlike Mongrel, you don't end up with per-worker queues. Though HAProxy is smart about distributing load well, Unicorn makes it seamless. The workers simply ask for a new request and the Kernel gives it one.
There are some other niceties too. Unicorn processes are forked from a master process. If you are using REE, they can keep Rails in a shared memory. When we deployed it, we dropped memory usage by 30%.
On top of all that, Unicorn's flawless rolling restarts are a pretty big plus.
In conclusion, if you're in the top 10% of Rails apps by traffic, give Unicorn a look. It is likely that switching over is worth the dev risk and cost. Otherwise, keep it on your radar, but don't consider it a must-have.
[reference]
From what I've seen so far, peoples' experiences with both Phusion Passenger and Mongrel/Unicorn can vary drastically. Some people noticed a huge response time drop and performance increase when they switch from Mongrel/Unicorn to Phusion Passenger, others experience the opposite. I guess it depends a lot on the server. Phusion Passenger has got some pretty heavy users though, e.g. the New York Times Obama real time election results page was running on Phusion Passenger. The Dutch national TV broadcasting organization is running all their Rails apps on Phusion Passenger and they get huge spikes of traffic whenever something is mentioned on TV.
Tomorrow's headlines: "Twitter is killing Unicorns"
We've done plenty of simulations, load tests, and lots of graphing that shows ngnix's performance gains are negligible given our hardware configuration. We've also got huge dependencies on mod_rewrite right now and didn't want to convert to ngnix for that very reason.
There seems to be this awful myth, completely unsupported by science, that seems to state that unless you're running Rails with ngnix that you're doing the wrong thing. The prevelance of ngnix in the Rails community is astounding.
It's a good server and it certainly has it's place in the world, but it's just not for us and not supported by our benchmarks.
Tremendous, in this case, is because the extremely low resource usage of nginx allowed us to remove an entire layer in our serverfarm flowchart and now we can use our machines much more efficient.
Thanks for the bluepill link though, we'll take a look at it and might consider a rewrite of our internal tool at some point.
I'd like to open source Stormcloud when it becomes more accessible. Unfortunately, it's laden with internal dependencies to our monitoring systems, and not publicly consumable at the moment.
I still think passenger is great for low demand sites. It took a while to figure out everything that had to be done for unicorn, which included a proper unicorn config file, a rake task to start/stop/restart, and a matching init.d script for my ubuntu; I also wrote a rake task to install the init.d script. Someone should post that stuff online.
Someone, please try this the next time you go shopping, and then blog about what happened.
These days however, almost anything is faster and more stable than apache under load. It's really starting to show it's age unfortunately.
(and darn I wish we had a Fry's here!)
Wow.