123
 123

Sat 20 December, 2008

Click here to bookmark this link.Channel Image09:33 Performance of Rails Metal» Riding Rails - home

Josh recently added Rails Metal, which has been getting a fair bit of publicity. Metal is a great piece of functionality for those rare cases where the speed of your framework actually matters.

However, people have been reporting 25x speed increase over a regular Rails action, and that just doesn’t seem right. So I decided to do some benchmarking of ‘Hello World’ Rails action v/s Metal. Here are my results :

Rails action

Time per request : 1.244 [ms]
Throughput : 800 request/second

Metal

Time per request : 0.386 [ms]
Throughput : 3000 request/second

You can find more details about benchmark command/code at http://gist.github.com/38080

Of course, these are not very scientific benchmarks and your results may vary a little from what you see here. You should also make sure you run your benchmarks in production mode.

Now, if you compare these results, 3000 r/s against 800 r/s, you may think you’re seeing a 3x performance increase. However, that’d a wrong perception and throughput isn’t the best metric here.

Difference in Time per request is what you should looking at. In my benchmarks, speed increase I get when using Metal is about 1 millisecond. And that’s a constant speed increase I’ll get over a regular Rails action. It’s very important to understand that it’s a constant speed increase. It’ll always be 1 ms for me.

For example, if my Rails action takes 12ms, when I reimplement it all in Metal, it will take about 11 ms and not 4 ms.

To conclude, I’ll just quote DHH :

But for those few, specialized cases where you just need as much raw speed as possible, Metal can be exactly what the doctor ordered. It allows you to have the best of both worlds in one package. The lowest possible overhead for a Rack application when that matters and the full-featured goodness of Action Controller when it doesn’t.


add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image04:56 This Week in Edge Rails» Riding Rails - home

December 13-December 19, 2008 Edition

The Rails team hasn’t been hibernating this week: 50 commits hit the edge branch, from a variety of developers. Here’s my pick of the most interesting and significant new core code for the week.

Rails Metal

If you’ve been keeping in touch with Rails at all, you’ve heard about Metal this week: superfast endpoints inside of your Rails applications that bypass routing and Action Controller to give you raw speed (at the cost of all the things in Action Controller, of course). This builds on all of the recent foundation work to make Rails a Rack application with an exposed middleware stack. Rather than explain Metal in more detail, here are places you can read more about it:

Rack-based Session Stores

A big change pushed the underpinnings of Action Controller session storage down to the Rack level. This involved a good deal of work in the code, though it should be completely transparent to your Rails applications (as a bonus, some icky patches around the old CGI session handler got removed). It’s still significant, though, for one simple reason: non-Rails Rack applications have access to the same session storage handlers (and therefore the same session) as your Rails applications. In addition, sessions are now lazy-loaded (in line with the loading improvements to the rest of the framework). commit

A related change provides persistent session identifiers for cookie sessions, with API compatibility with the server-side stores. commit

MIME Type Handling

There are a couple of changes to the code for handling MIME types in Rails. First, MIME::Type now implements the =~ operator, making things much cleaner when you need to check for the presence of a type that has synonyms:


if content_type && Mime::JS =~ content_type
  # do something cool
end

Mime::JS =~ "text/javascript"        => true
Mime::JS =~ "application/javascript" => true

The other change is that the framework now uses the Mime::JS when checking for javascript in various spots, making it handle those alternatives cleanly. commit commit

Active Record Cleanup

Even though Active Record has been a core part of Rails basically forever, people are still eking out performance and usability gains here and there. This week saw commits to stop generating some useless queries when working with belongs_to associations (commit), give better error messages on failed find_by_foo! calls (commit), fix some association preloading issues (commit and commit), and improve performance with the MySQL adapter (commit).

Odds and Ends

Remember the cleanup for noise in the log files that edge got a couple of weeks ago? Building on that, we’ve now got prettier printing for output from any Gem in the backtrace. commit

If you’re on edge, Rails now enforces the requirement for Mocha 0.9.3 or higher, so that you can run the tests. commit

ETag handling has been cleaned up a bit: Rails will now skip sending an ETag header when there’s no body to the response or when sending files with send_file. commit

If you want to track down who worked on Rails in the past, it’s gotten easier thanks to a huge data collection and patching effort by Xavier Noria: he went through all of the changelogs and normalized author names, so we don’t have the confusing mash of names, handles, and email addresses in there any more. commit


add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image04:56 Hollywood Release Windows Suck» Joey Gibson's Blog
A couple of weeks ago I extolled the virtues of my new Netflix Player. I’m still thrilled with it, but the other day I happened to be looking at my instant queue from a web browser, and I noticed several lines in the queue that looked like this Notice anything about that? Yeah, it’s the “Available [...]
add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl

Fri 19 December, 2008

Click here to bookmark this link.Channel Image20:12 取材» Matzにっき
「アエラを見ました」というのがきっかけで取材を受ける。 少林寺拳法の機関紙なのだそうだ。 拳法? が、バックナンバーを見せてもらったが、 ぜんぜん格闘技とか拳法とか関係ないインタビューが 毎号載るのだそうだ。 よかった、どうしようかと思ったよ。
add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image20:12 あぶない» Matzにっき
昼食後、電子レンジからなにやら音がするな、と思ったら すっかり熱くなっていた。外見上は動作していないのに、 オーブン機能が暴走でもしたか。 ドアをあけたら煙がモクモク。 もう15年くらい前の古い電子レンジ(オーブン機能付き)なので、 壊れても不思議ではないのだが、 うっかり気がつかないで出かけてたりしたら火事になってた。 危険だ。
add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image04:00 Talkbox via Nintendo DSi» Projectionist
Click here to bookmark this link.Channel Image04:00 Man is least himself when h...» Projectionist
Man is least himself when he talks in his own person. Give him a mask, and he will tell you the truth.

Oscar Wilde


add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl

Thu 18 December, 2008

Click here to bookmark this link.Channel Image14:00 Introducing Rails Metal» Riding Rails - home

Rails Edge adopted Rack a while back and we’ve been exploring ways to expose that better. The first thing we did was to make it really easy to hook up any piece of Rack middleware in front of a Rails request. In your config/environment.rb file, you can do:

config.middlewares.use(Rack::Cache, :verbose => true)

This will make your application use Ryan Tomayko’s excellent Rack::Cache middleware for better HTTP caching. There are lots of other great generic, reusable Rack middleware pieces. Do go shopping.

But there’s another use case where Rack also comes in handy. If you have a Rails application that has service end points that need to be really, really fast. So fast that the few milliseconds that a trip through the Rails router and Action Controller path is too much.

For this scenario, we’ve built a thin wrapper around the generic Rack middleware and given it a place in the hierarchy along with the name “Metal”. Rails Metal is meant for things like the Campfire poller service, which is doing hundreds of requests per second and needs to be really fast and is at the same time really simple (2 database calls and returning a string). This service is currently written in C, but we’ll look into converting it to Rails Metal instead.

Rails Metal is a subset of Rack middleware
Think of Rails Metal as a subset of middleware intended for application-specific end points that need the extra speed (“write to the metal”, hence the name). Thanks to recent adoption of Rack sessions, these pieces of metal even have access to the same session as Rails. You can either run them as part of the Rails process or run them as individual services through rackup.

We’ve even included a generator for Metal, which by default will create a stub ala:

class Poller
  def self.call(env)
    if env["PATH_INFO"] =~ /^\/poller/
      [200, {"Content-Type" => "text/html"}, "Hello, World!"]
    else
      [404, {"Content-Type" => "text/html"}, "Not Found"]
    end
  end
end

As you can see, all this does is capture requests to /poller and return “Hello, World!” (and the request is not for /poller, it’ll let the Rails router handle it—that’s what the 404 return does). It will do that just about as fast as is technically possible in Rack (cue useless metric of how Rails now has the fastest, most meaningless “hello world” stat!!).

Note that this is a pretty specialized tool. While you could write an entire Rails application using just metal, it would be a terrible idea in most cases. The vast majority of applications out there will never do what they do so fast that the overhead of the already heavily optimized Rails router and Action Controller execution path will matter one bit (pick up Michael Koziarski’s talk on Rails Performance through torrent for more on this).

Also, if you’re writing a generic filter in the vein of Rack::Cache, Metal is not the right choice either. You should just be creating regular middleware which can be shared across all Rack applications.

But for those few, specialized cases where you just need as much raw speed as possible, Metal can be exactly what the doctor ordered. It allows you to have the best of both worlds in one package. The lowest possible overhead for a Rack application when that matters and the full-featured goodness of Action Controller when it doesn’t.

We hope you like this. Josh Peek has putting tireless hours into getting Rails on Rack and this is just the latest product of his efforts. Thanks a bunch, Josh!

Update: Jesse Newland wrote up a great introduction to Metal as well. It includes benchmarks and even more examples!

Update 2: Changed code example to match latest style.


add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl

Wed 17 December, 2008

Click here to bookmark this link.Channel Image09:56 Templates Offer Rails New Path to Ubiquity» O'Reilly News:Ruby
Rails application templates, just added in Edge Rails, offer Rails developers the chance to spread their wings and bring Rails to new audiences and new capabilities - and might even help Rails lead the next generation of frameworks.
add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image02:28 Hosting Ruby on Rails with Passenger» Riding Rails - home

Phusion Passenger aka mod_rails has been on a tour de force lately and rightfully so. It makes Rails deployment so much simpler and combined with REE faster and with less memory overhead. So I’m really happy to see that lots of the hosting companies in the Rails world are adopting it and making it available to their customers.

Rails Machine recently announced that Passenger is now part of their standard stack and that they’ve made it silly easy to switch from a Mongrel-based setup to Passenger. The latest Accelerator from Joyent has Passenger preconfigured as well. At the shared hosting end, Dreamhost has been supporting Passenger for a while (nice tutorial using Passenger at Dreamhost).

I’ve personally been setting up Passenger at Slicehost with Ubuntu and having great results with that. At 37signals, we’re already running Ta-da List (on EC2) and Backpack (at Rackspace) on Passenger and plan to move over the rest of the applications shortly. Our system administrators certainly appreciate not having to funk with Mongrels any more.

Lots of other hosters are in advanced testing with Passenger as well. Brightbox has been building Ubuntu packages for Passenger and is putting one together for REE. They should have complete Passenger support shortly. Most other Rails hosters I’ve talked to are at least looking into it as well.

But just because Passenger is a big step forward for Rails hosting, it doesn’t mean that other approaches are suddenly useless. There may still be situations where a traditional proxy/Mongrel setup would be relevant. For example, if you for some reason are unable to use Apache, that’s still the way to go. Rails will continue to support both FCGI, proxy/Mongrel, any Rack web server, and of course Passenger.

The change is that if you do not already have an investment in an alternative solution, or if you’re feeling pain with that solution, you should definitely consider Passenger to be the default choice for Rails.

Update: Phusion has posted a guide to how you control the Rails and Ruby environment variables under Passenger. Useful for tweaking the GC settings etc.


add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl

Tue 16 December, 2008

Click here to bookmark this link.Channel Image03:37 Videos from RailsConf Europe '08 live» Riding Rails - home

Blip.tv have published the five keynote videos from RailsConf Europe 2008. It includes Jeremy’s excellent talk on Performance on Rails and my own Living with Legacy Software. Check ‘em out.


add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image03:37 Videos from Paris on Rails '08» Riding Rails - home

I love how so many conferences are recording their sessions. Paris on Rails is another of those conferences and they’ve recently published their recordings as both video and audio. Most of these sessions are in French, but Michael Koziarski did a great session on Rails Performance that’s in English and so was my iChat Q&A session.


add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl

Sun 14 December, 2008

Click here to bookmark this link.Channel Image23:24 五年,在blogbus» 梦想风暴
出差在上海,刚好是blogbus组织一次用户恳谈会,我有机会出现在那个传说中由仓库改造而来的办公室。对我而言,总有一些微不足道的梦想会在五年的时候实现。毕业五年之际,我重回到了自己曾经奋斗过的大学校园。时值写blog五年,我有机会参观了blogbus。

是啊!五年了!

blogbus恳谈会,听着其他用户谈论着在blogbus的心路历程,我也不断回想着自己五年的blog经历:读《程序员》第一次知道blog,第一次听说blogbus;在blogbus写下了《开始“信口开河”了》;曾经,blogbus中断半个月,让自己第一次感觉到对blog如此依赖;曾经,两个月没有写一篇blog,回来后告诉自己,无论多忙,写blog也应该继续下去;第一次看到自己的blog被别人转载,心中暗自窃喜;第一次有人要把我blog的内容发表在杂志上;第一次收到自己blog读者的email……

如今,blog已然成为我的生活方式:用blog的方式纪录着想法,让自己养成了总结的习惯;通过blog结交着各种各样的朋友,给自己带来了很多的机会;每天都会到blog上来看看,看看是不是有了新的评论……

五年前,blogbus并没有很明显的风格,而那时,也没有专属于技术人员的blog。如今,blogbus已经有了很强的特色,这一点从恳谈会的参与者也能感受得到,而现在的技术blog也越来越多,有不少朋友也希望我搬迁到其它blog上。用户恳谈会上,有这样一个问题,什么让你选择留在bus上。我的答案是,习惯。只要bus不让给带来另类“惊奇”,我相信自己还是会继续在blogbus经营下去。

路,要继续走;blog,要继续写。




add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image22:43 计算机世界:创造你的计算机程序语言» 天天红玉世界
创造你的计算机语言
  • 说明
    • 你是否在创造。。。

      a full programming language
      完整程序语言,
      a domain-specific language
      特定领域语言(DSL)
      a simple data format
      简单数据格式,

    • Waxeye将使得你变得更快。

add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Click here to bookmark this link.Channel Image22:33 Zum dritten Advent» chris blogs

Schon wieder Sonntag…

Bei wrongcards gibts “ecards that are wrong for every occasion!”, zum Beispiel diese:

Jetzt mal noch die Plätzchen alle machen… leider keine mit Bacon.

NP: Oceansize—Only Twin


add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl

Sat 13 December, 2008

Click here to bookmark this link.Channel Image19:04 Rails2.2世界:国际化功能问与答(四)» 天天红玉世界
国际化功能问与答(四)
  • 本地化问题(四):本地化工作方法
    • 重新载入本地化文件命令:
      I18n.reload!
    • 设置当前本地化语言
      I18n.locale = “zh-CN”
    • 查看当前本地化语言
      I18n.locale
    • 查看本地化内容信息
      I18n.t “time.formats”
    • 简化本地化函数方法
简化本地化函数方法
class String
def t(locale="zh-CN")
I18n.t self.to_sym, :locale => locale
end
end
"hello".t
"hello".t "en"

add to del.icio.us add to del.icio.us. look up in del.icio.us.   add to furl.net add to furl
Sources