#150 Rails Metal
Feb 23, 2009 | 9 minutes | Performance, Rails 2.3
Rails Metal is a way to bypass the standard Rails request process for a performance boost. In this episode you will learn how to shave off a few milliseconds using Metal.
- Download:
- source code
- mp4
- m4v
- webm
- ogv
Thanks Ryan for this screencast and congratulation for #150!
Again a great episode on performance tuning!
Determining what actions might benefit from metal should be determined by analysis of request times, to avoid the trap of premature optimization. You can use request-log-analyzer (wiki.github.com/wvanbergen/request-log-analyzer) to analyze the request times from your logs. (Full disclosure: I am one of the authors.)
Note that after you have rewritten an action using metal, it will NOT show up in the logs and therefore it will no longer be included in performance reports generated by request-log-analyzer.
Ryan, how Metal is different than Rack? Is Metal just Rails effort to be Rack compatible? Please excuse my ignorance.
Great screencast Ryan. Very interesting topic, and a very good use case for Metal.
Congratulations and a big Thank You! for your 150 railscasts. Great job!
Great screencast... I've heard of metal before but this made me go and try it out. Thanks!
I was testing a few things out using apache bench after I watched the episode, and perhaps something you should have mentioned was how to kill the detached server process. I never knew how to do this, and I ended up killing ruby and restarting it to kill the server listening on port 3000. If anyone does know how to do this off hand, I would love to know.
Thanks
Haha~, I am refreshing the home page many times today for this episode. Great screencast! Thank you.
Rails Metal is a thin layer above Rack, just like Sinatra is, and Sinatra is doing this way before Rails Metal appeared ... Rails Metal like Sinatra is a thin DSL above Rack so you don't have to code pure Rack and instead can code a simplified language above Rack. What I don't get, is why someone would use Sinatra app inside a Rails app (see some sample on the web), since you can use Metal or better, pure Rack inside Rails.
Hey Ryan, congratulations on episode 150. I've really appreciated these railscasts every week. Keep up the great work!
Hey Ryan,
You are truly the man! Thanks so much for all the work you do. It has really helped me over the past year, and I hope it will continue for years to come!
Hi Ryan, many thanks for your wonderful screencast !
A simple question: is it possible to use metal for multithread execution or large upload handling ?
Please make sure to read over this post before getting too involved with your metal :)
http://weblog.rubyonrails.org/2008/12/20/performance-of-rails-metal
150 amazing screencasts ! A big thanks Ryan !
Another Great episode! Keep up the good work.
Ryan, with today's episode, I've just caught up on all the Railscasts -- well, except all the e-commerce ones because I don't do that. Yet.
Congratulations on 150 episodes, and thanks for doing this for two years! You've provided me with a much better insight into the way Rails operates, and I've incorporated at least a dozen tips from your casts into my daily coding.
Ryan, I just want to say thank you for all your great work. Each week a great highlight. Please continue !!!
Thanks !!!
Ryan, thanks for those excellent screencasts, I owe you too much.
I've a problem with my Rails 2.3 installation in development mode:
When I load a page in Safari I've get no response at all, nul, the source code is an empty page, the same for curl but in Firefox it displays allright.
Any sugestions?
Here's the notes I took during this screencast:
RailsCasts Notes: #150 Rails Metal
* Bypass rails routing
* Simple request that happens frequently.
* to generate: ruby script/generate metal name_of_metal
* stored under app/metal/
* in the generated code, the self.call(env) method should return an array.
1. response code ex. 404 or 200
2. hash of header options
3. Body content
* Won't be recorded in log file since it bypass that as well.
* When creating/changing a metal, you need to restart server (may change)
* If there is a conflict between Rails routing and metal, metal wins because it gets the request before rails has had a chance to process it.
* "ab -n 100 http://127.0.0.1:3000/processes/list" will run a benchmark that you can use to compare performance (just replace the url of page)
Originally at: http://railsnotes.wordpress.com/2009/03/08/rails-metal-screencast-by-railscasts/
Is there any special requirement to make metal apps work with Passenger? In my setup Mongrels work Ok but Passenger silently ignores metal apps.
Helpful? I love you, man!