PHP vs Ruby on Rails, Part 3
In part 1 of our series we explained how PHP is just a language, not a framework; in part 2 we talked about Ruby’s object-oriented foundations and its cool iterators. Today we are going to finish our series with some thoughts on deployment. More specifically, we will discuss why deploying a Rails app is a little harder than PHP. If there is one thing that has me down on Rails it’s deployment. When I say deployment I don’t actually mean the act of uploading a new release. That’s actually very easy to do with a tool called Switchtower. No, I’m talking about using a shared-hosting provider. Dedicated hosts are easy to get going with Rails, but when you are using a shared box there is a little more to take under consideration. Let me explain.
The first reason why shared-hosting environments are tough is simply because Rails is still so new. PHP was the same way when it first started getting popular. These days however, I’d be shocked if any shared-hosting environment didn’t offer some level of PHP support. The second reason is because running a Rails application properly requires more resources and power given to the users on that shared box. Because of this most system admins of shared-hosting setups are rightfully cautious.
I can’t say I know exactly why Rails needs so much more “oomph.” The big thing to keep in mind is how most CGI environments work. The web server will normally build up the environment for the CGI, execute the code, return the HTML that was built to the client and then destroy the environment. It does this every time a request comes in. Now, it could be that Ruby is a little slower than PHP, but I suspect the main bottle neck is something else. If I recall, Rails inspects the database to help build the models it will use. Doing so every time could easily add a lot of overhead and thus cause a slow down. Anyway, without getting too specific(for I know not what I speak, err type), Rails is really slow when run under CGI. To speed things up we need FastCGI!
In a production environment, most Rails applications are being run under a thing called FastCGI. The main benefit of running Rails under FastCGI is speed. FastCGI will load and hold your app in memory so that it doesn’t have to build the entire environment per request. The negatives of FastCGI include extra CPU and RAM usage. On a box that might be shared between a hundred or so accounts it’s not hard to imagine how this might cause some problems.
Thus Rails on shared-boxes sounds bleak, but there are companies out there advertising such services. Now, most hosts on that page mention monthly fees so low it’s scary to think about how bad the service might be. For those not interested in playing web host roulette, let’s talk a little about the most popular of the shared-hosting + Rails setups, TextDrive.
I have no personal experience with TextDrive, but my biggest concern with them is reliability. They sell themselves as a company with bleeding edge technologies, and from what I read on their forums and third party blog posts, they tend to bleed regularly. I suspect lots of people are/were signing up for their $12/month plan, using it as a development server and constantly breaking things. I also suspect that the company continues to have growing pains. Perhaps, as they get more comfortable, and Rails more stable, things will get better. Another thing that might help is the fact that TextDrive is introducing Business Hosting Plans which promise “an average of only 20 customers per high-end storage-attached server.” The less crowded servers will more than likely have much better reliability —- we’ll see.
I’d would just be thrilled if Pair started to support Rails. I’ve been using Pair for a few years now and love their service. I also loved the chocolates they sent me for Christmas.
When it comes to the Clickable Bliss site, I’m currently using Pair for DNS+Email and pushing all web traffic to Zelda, my little Mac mini server. It’s working quite well so far, but with only myself and a dozen or so friends hitting the server on a regular basis there really isn’t all that much to do. In time I may move to TextDrive or a similar service. I have a feeling over the next 18 months we’ll see a huge increase in the number and quality of hosting providers offering Rails-application hosting.
That’s the skinny on deployment for small (shared-hosting sized) Rails applications. It’s a little tough right now, but I have a feeling it will get better soon. For those interested in launching bigger apps on dedicated hardware, don’t blink when it comes to Rails. It is as easy (or easier) than what you have previously used.
Posted on: December 27, 2005 – 11:03 am


28 Comments
Related links: James Duncan Davidson has recently posted some good talk about deploying Rails:
“I can’t say I know exactly why Rails needs so much more “oomph.””
I can - its because everything is an object. Even empty objects need to be allocated memory. Additionally, while constructing all these objects there is the ineviytable CPU overhead.
Additionally, a lot of the resources per request are completely unused, resulting in wasted CPU cycles and memory, all for the benefit of what? A distributed development timescale that is no quicker than the equivalent PHP framework.
This is why a bespoke, targetted, and minimalist frameworks are infinitely ‘better’ for a large scale application. A simple database select and display in procedural PHP can be CONSIDERABLY faster than the equivalent functionality in rails.
To Matt:
You say that rails is a waste…why then do enterprises use Java when everyone in the world knows that Java is a pig?
because they can afford it being a pig… most really slow enterprise websites you come across on the web seem to be Java based.
To Ben:
This was a discussion about PHP vs RoR, and it is that my comment specifically targetted.
Java is a completely different beast. First off, like PHP it is a language, not a framework. Its only similarity with Ruby (the language) is that it is an OO language.
When you say enterprise, what exactly is it that you mean? I would assume that you mean a website for an enterprise that just so happens to use a jsp tier, as you dont seem to understand what java is used for enterprise-wise?
Specific frameworks for specific enterprise applications are generally more efficient and easier to manage in Java over the traditional C/++ equivalents. The resource to develop these applications is thick on the ground, and development time is not the largest priority. Scalability vs. Cost, Reliability and Managability (usually in that order) are among the highest of priorities in enterprise application development.
How can you even begin to compare a framework like RoR to an enterprise application such as a telecoms system supplying 300m users with their mobile telephony requiremements?
If you ever need web hosting (with rails) check my site out at http://ww.thehostguru.com as I list only reliable web hosting companies.
Media Temple seems to have an interesting Rails hosting solution. They bill their virtual solution as a “grid” server. Sounds like a great idea in theory. I make the assumtion that these guys are pretty good based on some of their clients.
Nice article Mike. The related comments inspire me to ask:
( and Excuse me if I seem a little dreamy )
Taking Moore’s law into account; isn’t it only a matter of time before processor speeds become fast enough so that the difference in power required to run procedural code vs. OO code will be negligent? At that point won’t the best tool be the one that suites the developer rather than the computer? And isn’t that what Ruby is all about
( ie. written for the benefit of the developer not necessarily the computer )?
I am interested to hear feed back. also: really like the spam filter.
hmm, Sorry that my comment wasn’t directly relevant to the article. I thought it was interesting in regards to the comments.
Sorry if anyone felt threatened. Very Best
Joe, yes, cpu speed will continue to increase, but, for large scale websites so do the user bases. so if you have a choice between php or rails, and rails eats up more resources, it makes more sense to go with php. sure, for a personal blog it matters little, cpus on shared systems get bigger. but when you’re in the millions of users per hour count…. I’d like to write my own functions, and know they’re not wasting any cpu time, ..
I believe that the trend is towards scripted languages. Why? The code is increasingly having less value than the data.
So unless the business is a very proprietry, sharing the code , open sourcing it, is expected.
@joe and @adam @everyone else willing to read…
Put it this way (considering Moore’s Law):
I’d say that the more computing power and memory increase over time, the more you will find demands seeking to fill that power, especially as software evolves to become more advanced and complicated over time.
Now with that taken into consideration, if you have several languages/frameworks all competing for the best performance, implementation, scalability, interoperability (ad nauseam), ultimately one or two will come out on top. The best will thus have the greatest momentum for those future applications that will be demanding the most resources…
And also, think of it this way: * You have C, a language, not made for web development. * You have Java, a language, not made for web development. * You have Perl, a language, not made for web development (but commonly used as such) * You have C#, VBScript, all languages, not made for web development but (i believe) implemented with frameworks as ASP/X that do use them for web development.
Finaly: * You have PHP, a language, that IS made for web development. ** Make use of PHP’s built-in language-based web functionality and utilize PHP’s blazing speed! ** Additionally, you can find frameworks for it (EX: CakePHP is alright) ** Better yet, do what I do and develop your own framework on sound principles and hash out your own applications in NO time flat.
:)
PS: I love PHP.
CRAP, I also amazingly forgot to mention:
PHP as a language alone is native to the scene of web development. That, to me (notwithstanding other very serious advantages), is more than enough to maintain superiority overall.
See my latest article on this here: http://www.catchyour.com/blog/
I have visited your site 310-times
What are everyone’s thoughts on Lunar Pages?
Their basic hosting plan is crazy cheap, for a lot of space and bandwidth, and lists support for Ruby on Rails… http://www.lunarpages.com/basic-hosting/
DreamHost (.com) is cheaper because you are allowed to host as many websites you want with plenty of space and they support RoR, although I don’t know why you’d want to use it ;)
The reason I mention that it’s ok to host as many sites as you want is, from when I used to use LunarPages, they flat out said that it was against their TOS to host any websites you don’t own. So, with that said, if you plan on reselling your space, you’ll be in conflict with their TOS and live in fear of loosing your hosting account, so you’d expect to spend that same yearly fee for EACH site as well… btw, it’s also obviously against their TOS (as anyone’s TOS) to setup different accounts but save money by “referring” yourself to their service.
Just my thought on that, inc ase you are into hosting for people other than just yourself.
I’m a long-time PHP developer, but I develop in a couple of other languages that I’ve used over the years. I’ve programmed with other languages derived from Ruby (not Rails, yet) and my answer is… … …I’ve got to try something before I make a comment on it. No matter how much I read about it, I can’t know for sure until I get my hands a little dirty, so to speak.
I can understand why it’d be slow, and why it may take a while for the shared hosting to adopt RoR, but with the speed at which the internet and technology evolves, I doubt it’ll be long. For example, one of my web hosts has recently added RoR to their arsenal, so I will probably be testing it out soon.
The very least I can say is that the Ruby-based languages I’ve used are fun. =)
PHP is great, PHP5 has greatly improved its OO, and PHP6 will do even better. Cake and PHPRails are great frameworks and are much less cpu intensive then Rails and Ruby.
The main advantages of Ruby on Rails is DRY or Don’t Repeat Yourself. Programming in PHP made me repeat my code quite often for templates and such. Also being able to run a WEBrick server on your local machine without making the changes live helps.
You mentioned before that many big enterprises use slow languages such as Java. The reason for this is that the companies hire a developer or a team of developers to make the website. To save time, the developers use a quick-developed, resource-hogging language. The enterprise can’t even tell the difference. So if it helps the developer, it will be used.
What hooked me on ruby on rails was the fact that many of the problems of web development are addressed with clever solutions that not only work, but can easily be taken apart and changed by someone with limited intelligence such as myself.
For a long time, I’ve been thinking it shouldn’t be that hard to test web apps. You just need to run request parameters thru a piece of code, right? Do I really need Mercury Interactive to do that? Turns out I just needed Rails.
And why the heck do I need to code to these EJB monstrosities or tell Hibernate whats in the database? Turns out Rails just looks at the database and figures it out for you, and does it all the time when you are in development mode. duh.
And speaking of development mode, Rails doesn’t make me compile everything or tell it that I changed a file or make me reload the browser or bounce the server. It simply finds the latest stuff when things change.
Simply put, Rails relieves from having to do a lot of tedious stuff that computers do quite nicely. Would I prefer that it be easier to learn Ruby (there is still agony to be found in Ror)? Yes. Would I rather it ran as fast as my code were implemented with transistors? That’d be cool.
I’m not that big a fan of dynamic typing, especially when that slight typo confounded me for hours by making Ruby see two variables when I thought I was dealing with one. Developer productivity? A 10 to 1 increase? Not on your life. Maybe this will change with more experience. You do write less code, but it ain’t free.
Rails is many good ideas that will someday take over much of web development. But there are a few things that need fixing too.
the problem with cake and other rails-like php frameworks is that that there are way to many of them. and there are no books, at least there weren’t for cake when i was trying to make it work
“Rails is many good ideas that will someday take over much of web development. But there are a few things that need fixing too.”
I am sorry but Rails is not going to take over much of web development like PHP IMO. I am sure by the time ruby become faster, which i don’t think it will ever be as fast as php, I bet there will already be a very good port of rail to PHP. Like i said on another page here, using a language because of a framework is retarded.
Also says “Throw more power at it” when something in rails runs much slower than php is also a poor way of fixing things.
Why on earth should framework functionality be incapsulated inside the language interpreter???
this RoR “Feature” which is basically what makes code thinner is Exactly the kind of thing you should avoid in web development because you loose flexibility and become a rather stupid developer, you no longer build Web Applications, you build “Rails” Applications.
I’ve built pretty complex, restful applications in PHP for ages and after testing ruby i’m pretty confident i’ve made the best choice.
“Ruby inspects your database to optimize the datamodel????” are you kidding me, how on earth is that a feature for serious developers?
Yea one thing I found it for sure it that rails looks at the database model and create the structure every time you run it which is very inefficient.
This is a great overview for someone just starting out with Rails - and its over 2 years old! Thanks for the thoughts and summary on these two web development options.
Jan 2008 Well, I did not read all comments, but, about speed and memory … php as cgi uses lots of memroy and is very slow, so it is ruby, but Ruby may function as an apache module like php. Does anyone know about speed and memory differences in this arena?
I use Speedy Rails. Good RoR support and they are Canada, eh? :-)
Post a Comment | Comment RSS feed