Rails Development and Deployment

I've been reading up on Rails incrementally, and it looks like FastCGI is the preferred deployment method. I'm not sure how I feel about this. My past experiences with FastCGI is that it's, well, not the most lean bit of code out there. I'm curious if anyone knows this to be different now, particularly on FreeBSD.

At the moment, I'm using my own PHP-based framework for web development, so I'm trying to decide if I should look at using Rails, or continue to develop/refine the system I have and eventually release it to the public. I've found PHP itself to be just an unbelievably fast performer, so I still need to see how Ruby can match up in that department.

It also seems that perhaps there's some sort of fundamental issue with Apache and FastCGI that can make it unreliable. Some people seem to suggest using lighttpd. Apache has been so good to me that I'd need a really good reason to use something else.

As for the Ruby syntax itself, it's been a mixed bag. Some bits are quite elegant, others are just far too obfuscated for my taste. I also think the language itself might have too much syntax. My experience with Cocoa has made me a real believer in the value of reducing ambiguity and syntax complexity.

One of the reasons I don't use Perl is that there's just too much special-purpose syntax. I don't object to that because it's hard to learn, but because it's not great when you're looking at someone else's code. I think one of the reasons Objective-C is so effective is that there's very little syntax. If you understand the syntax for one Cocoa app, you understand almost all of them.

I also prefer Cocoa/Objective-C's explicit naming conventions. I've seen a lot of Ruby code like this:

def bfs(e)
   q = []
   e.mark
   yield e
   q.push e
   while not q.empty?
     u = q.shift
     u.edge_iterator do |v|
     if not v.marked?
       v.mark
       yield v
       q.push v
     end  
   end
end
bfs(e) {|v| puts v}

As well as this:

class Person
  def initialize(name, age)
    @name, @age = name, age
  end

  def <=>(person)
    @age <=> person.age
  end

  def to_s
    "#{@name} (#{@age})"
  end

  attr_reader :name, :age
end

group = [ Person.new("John", 20),
          Person.new("Markus", 63),
          Person.new("Ash", 16)
        ]

puts group.sort.reverse

(both from Wikipedia's Ruby page)

Most Cocoa programmers I know would probably wince at this. It just feels too terse. Less characters doesn't necessarily mean the code is easier to read. Don't get me wrong, I find Ruby to be a lot of fun, but clarity is absolutely vital.

Back to Rails, I'm still trying to figure out what the "it" factor is. Maybe I'm spoiled by Core Data and WebObjects, and maybe I have a different perspective from writing persistence engines myself, but I haven't yet indentified a "top 5" kind of list for Rails beyond data peristence and integration with the Prototype library.

This is still very much an in-progress evaluation of Ruby and Rails, and there's plenty I don't know. The dependence on FastCGI for deployment is a stumbling block. I was really hoping for mod_ruby to fit the bill. I'm also trying nail down what the deal is as far as templating. I'm really happy with Smarty, but I haven't found its counterpart in the Rails world yet.
Design Element
Rails Development and Deployment
Posted Jun 29, 2005 — 23 comments below




 

Daniel Lyons — Jun 30, 05 286

I'm a big fan of both Ruby and Cocoa, though I have a lot more experience with Ruby. I agree that the users are sort of a mixed bag, but it seems most people are somewhere in the middle in terms of readability. Rails seems to really push for the latter though.

The "big idea" behind Rails is that you're not going to repeat yourself anywhere. I've played around with it and found it to be a really neat, fun development environment. You make the database, and then you just make a class with the name of the table, and it basically figures out the rest by talking to the database. The API is full of this kind of trick.

A couple weeks ago, I set up Typo, the Rails blog software, on one of my servers. I set up four deployments with FastCGi on Apache. Everything seemed to be working just fine, I gave out three of the logins to two other guys, and between the three of us, we managed to get the load average of the server up to 72 with four Rails apps loading up. I find this kind of astonishing.

So I would call it a pretty bulky framework, and I have zero confidence in FastCGI.

Since then I've been messing around with Drupal instead, which is more like a PHP web application framework. I strongly dislike PHP's syntax, but it's damn fast, and Rails (at least on Apache w/ FastCGI) is definitely not ready.

Rob — Jun 30, 05 287

With regard to your last statement about templating: Rails uses ERb (part of the standard library) for .rhtml templates and Builder for .rxml. The ERb syntax is simple, just embedded Ruby code with typical <% %> and <%= %> delimiters, and the templates have access to the controller's instance variables. Most templates are located automatically, under app/views/<controller>/<action>.r(html|xml).

On deployment: I think everyone just gravitates to FastCGI and lighttpd eventually because the combination does work pretty well for the Rails applications that are out there so far. The main sticking point for mod_ruby seems to be that it reuses one Ruby interpreter instance for all hits handled by a particular child process, so running multiple Rails apps on it at once is potentially unsafe. While that limitation makes it unsuitable for shared hosting, it should work just fine on a dedicated server, if that is the environment in which your app is going to end up.

Greg — Jun 30, 05 288

Just a pointer to yet another Unix web server: www.acme.com/software/thttpd/

Scott Stevenson — Jun 30, 05 289 Scotty the Leopard

Daniel: Thanks for sharing that. Interesting data point. You actually reminded me of another point I meant to make about Rails.

I'm a believer in the idea of the database being slave to the model, not the other way around. I think a dedicated model can be more expressive about the design than a SQL database schema.

Rob: Smarty is not your typical templating engine, which is why I was curious if Ruby/Rails had anything similar. It's an exceptionally useful too.

Neil — Jul 01, 05 290

Well, Perl certainly is not very easy to read, but there is an interesting website engine project called www.masonhq.com (which btw is used by Amazon.com). Also available for Perl: www.template-toolkit.org. And Unix command line gurus are at home at thewml.org (The Website Metalanguage, which is ugly but powerful, cf. engelschall.com/oss/).

Will Parker — Jul 03, 05 291

I'd certainly agree that anecdotal evidence appears to point to FastCGI as a real bottleneck. My question, as a Ruby newbie, is whether Ruby (and Rails) are tied to or otherwise dependent on FastCGI. How easy is it to use a different CGI module?

"I also think the language itself might have too much syntax."

The same might be said of English, Latin, French and Russian, but those languages seem to have survived the test of time. The question is whether accepting the burden of a complex syntactical structure offers some significant advantage in dealing with certain types of problems.

I'm exploring Ruby now because I got a taste of building an interactive web site with PHP, MySQL and Javascript in the past year. Taken as a bundle, I didn't much care for the taste.

I'm still new enough in Ruby that I don't have a good overall mental model, but Ruby, in combination with Rails and now {url=http://script.aculo.us/]the Scriptaculous Javascript library[/url] is looking more and more like a useful toolbox to me.

Aside from FastCGI, what other tools in the Ruby/Rails toolbox need to be replaced to produce a dependable, scalable Web platform? What is the likely cost of adopting the replacement? Who's working on that part of the solution?

Greg — Jul 03, 05 292

@Will Parker: I've found some Ruby CGI scripts at pleac.sourceforge.net! Also worth a look: web-graphics.com/links/tutorial/index.php. And for a ready-to-go Ruby web publishing tool see Contrepoint (www.mecanisme.net)!

Scott Stevenson — Jul 03, 05 293 Scotty the Leopard

is whether Ruby (and Rails) are tied to or otherwise dependent on FastCGI

From what I've seen, the only two supported deployment options are FastCGI and mod_ruby. The problem with the latter is that all applications share a single interpreter. So when Ruby loads a class, the class initialization affects all active applications.

same might be said of English, Latin, French and Russian, but those languages seem to have survived

It's not like people chose a language to speak when they're born. :) There's built-in inertia. In any case, I think software is much more sensitive to syntactical mistakes.

the question is whether accepting the burden of a complex syntactical structure offers some significant advantage in dealing with certain types of problems

A think you could make the case that just about anything can help you with certain kinds of problems. :)

I'm exploring Ruby now because I got a taste of building an interactive web site with PHP, MySQL and Javascript in the past year.

If you're taking about using PHP's procedural API, and JavaScript written from scratch, I agree. I use PHP as a low-level foundation for my framework because it's very easy to deploy and is ridiculously fast. I also think Smarty adds a lot of value.

the Scriptaculous Javascript library is looking more and more like a useful toolbox to me.

I hadn't heard of this -- thanks for pointing this out. It looks like it's based on Prototype, which is indeed a good library. Neither have to be used with Ruby, of course.

Aside from FastCGI, what other tools in the Ruby/Rails toolbox need to be replaced to produce a dependable, scalable Web platform? What is the likely cost of adopting the replacement? Who's working on that part of the solution?

The two issues I've seen so far are deployment and the (apparent) lack of a Smarty-like templating engine. I'm not sure what you're asking with the other questions.

Phil Ackerton — Jul 04, 05 294

A Ruby template engine is Kwartz (www.kuwata-lab.com/kwartz/). Esp. for Mac OS X there seems to be Tempura (www.fobj.com/software.html, but also see rubyforge.org/projects/pagetemplate/ and such projects as wee or hobix). For a FastCGI tool see www.moonwolf.com/ruby/archive/ and in general wiki.rubyonrails.com/rails/show/FastCGI. For some books on Ruby see www.pragmaticprogrammer.com. A good Tiger installation guide btw can be found at jamie.blogthing.com!

Peter Archer — Jul 04, 05 295

My Googling efforts have ended up with this: blog.unquiet.net/tag/osx/ (installing lighttpd on Tiger); blog.ideoplex.com/software/ (fastcgi patch for RoR); fastcgi.coremail.cn (a fastcgi replacement) & sqlrelay.sf.net; and www.linuxjournal.com/article/7922 (Ruby clustering with sqlite; not quite on topic but nevertheless interesting).

Tim — Jul 04, 05 296

An alternative to FastCGI is sf.net/projects/ruby-session/ !

Scott Stevenson — Jul 04, 05 297 Scotty the Leopard

What does ruby-session do? From the description, it sounds like it provides client sessions.

Tim — Jul 04, 05 298

It's kind of a Ruby servlet lib. For more information also check out www.codeforpeople.com/lib/ruby/session/session-2.1.10/. But I've also come across some users that use CGI & www.druby.org!

Jo — Jul 07, 05 301

Still looking for a flexible Ruby database management solution (that should also work RoR)? See the very interesting article on ObjectGraph over at www.rubygarden.org (Og is part of rubyforge.org/projects/nitro).

Scott Stevenson — Jul 07, 05 302 Scotty the Leopard

Og looks interesthing, though built-in database persistence is one of the main features of Rails. Maybe Og does something different that's not obvious.

Nick Fleming — Jul 08, 05 303

Does RoR support PostgreSQL out-of-the-box?

Greg — Jul 09, 05 304

Yet another HTML/XHTML template lib for Ruby is amrita.sourceforge.jp. A Ruby source code documentation system is rdoc.sf.net. A nice Unix-Ruby example is rmagick.rubyforge.org. Two more sources worth knowing about: www.rubycgi.org and www.joelh.de/selfruby/ (example code; only in German though)!

Jon Raphaelson — Jul 14, 05 306

I personally came to rails after having been an active rubyist for a while, and I think it really gave me some perspective on some of the hype. Frankly, my opinion is the whenever you are looking at frameworks and systems like this, try and match it to yourself as much as possible - if you are already a PHP kinda guy, and you like it, and you have stuff set up in it, then stick with it; it never hurts to play around with stuff though.

And make sure not to get caught up in the confusion many web minded developers seem to get caught in: rails != ruby. This is an extremely important point. Seriously, hanging out in #ruby-lang listening to people whine about ActiveRecord is annoying ;D

Jeff — Jul 26, 05 311

@Jon Raphaelson: How about www.nitrohq.com as a RoR alternative! As a CGI testing framework i've found WebUnit!

NC — Dec 07, 05 599

A deployment option for RoR that looks to become popular is utilising SCGI instead of FCGI.

SCGI plays nicely with Apache, is far easier to set up, and is still being maintained, unlike FCGI.

See http://www.zedshaw.com/projects/scgi_rails/ for more info.

TheBlatherskite — Nov 20, 06 2459

The dependence on FastCGI for deployment is a stumbling block.

The state of the application server world has changed greatly for rails since this article was written. If FastCGI is still holding you back, I'd recommend taking another look around. Lighttpd + Mongrel + Pound (on FreeBSD, in my case) in particular has emerged as a favorite among rubists, and there are a number of other viable options as well.

bnxhwka — Jul 23, 07 4540

http://betonsoldierbloodsporttrainer.kura.ewohseka.com/ http://betterbananasorapples.kura.ewohseka.com/ http://bettertogether.kura.ewohseka.com/ http://bettascreensaver.kura.ewohseka.com/ http://betrayalsings.kura.ewohseka.com/ http://betterthansexchocolatecakesundaynewyorktim.kura.ewohseka.com/ http://betterbodzcom.kura.ewohseka.com/ http://bethyacantdoitlikeme.kura.ewohseka.com/ http://betterbureaubusiness.kura.ewohseka.com/ http://betnovatecream.kura.ewohseka.com/ http://bettafishcolorsspotsonfins.kura.ewohseka.com/ http://bethparetta.kura.ewohseka.com/

roger pack — Jan 18, 08 5351

Fav. deploy seems to be mongrel + nginx.




 

Comments Temporarily Disabled

I had to temporarily disable comments due to spam. I'll re-enable them soon.





Copyright © Scott Stevenson 2004-2015