【前沿生活】Rails Metal - 让Rails2.3很好很强大
2008-12-21 03:35
281 查看
Rails Metal是Edge Rails的新特性。最近的Rails core team的工作是用rack取代了Rails老的request处理代码,并且集成了中间件的支持。Rails Meta允许你的Rails 应用使用Rack中间件来创建一个超级快的action。
无耻的转载国外同行写的简单的Rails Metal的hello word例子:
class Poller < Rails::Rack::Metal
def 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
对比一下老的controller:
class OldPollerController < ApplicationController
def poller
render :text => "Hello World!"
end
end
看一下两者的差距:
# first, let's benchmark the traditional controller
$ ab -n 1000 http://127.0.0.1:3000/old_poller/poller
... snip ...
Requests per second: 408.45 [#/sec] (mean)
Time per request: 2.448 [ms] (mean)
# now for the Metal middleware
$ ab -n 1000 http://127.0.0.1:3000/poller
... snip ...
Requests per second: 1154.66 [#/sec] (mean)
Time per request: 0.866 [ms] (mean)
看吧,Rails Metal 的性能要比老版本的controller快2.8倍 。。。
本文出自 “悟道集” 博客,请务必保留此出处http://blackanger.blog.51cto.com/140924/121460
无耻的转载国外同行写的简单的Rails Metal的hello word例子:
class Poller < Rails::Rack::Metal
def 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
对比一下老的controller:
class OldPollerController < ApplicationController
def poller
render :text => "Hello World!"
end
end
看一下两者的差距:
# first, let's benchmark the traditional controller
$ ab -n 1000 http://127.0.0.1:3000/old_poller/poller
... snip ...
Requests per second: 408.45 [#/sec] (mean)
Time per request: 2.448 [ms] (mean)
# now for the Metal middleware
$ ab -n 1000 http://127.0.0.1:3000/poller
... snip ...
Requests per second: 1154.66 [#/sec] (mean)
Time per request: 0.866 [ms] (mean)
看吧,Rails Metal 的性能要比老版本的controller快2.8倍 。。。
本文出自 “悟道集” 博客,请务必保留此出处http://blackanger.blog.51cto.com/140924/121460
相关文章推荐
- StarUML---推荐一款UML工具(很好很强大)
- 很好很强大的cUrl库
- 分享45个android实例源码链接,很好很强大.收藏吧!!!
- 强大的flash头像编辑上传插件(已更新至2.3)
- yield,很好很强大
- Ruby on rails开发从头来(四十七)- ActiveRecord基础(强大的find方法)
- 一个很强大很好用的报表统计插件
- MOSS的权限控制很好很强大的
- 45个android实例源码,很好很强大.收藏吧!!!
- 前沿 | 科幻变现实:盘点现实生活中最先进的半机械人
- 很好很强大的vimrc(带注释版)
- 众多Android 开源项目推荐 和分享45个android实例源码,很好很强大
- 总结分享下日常生活中用到的一些功能,很好很强大,功能很多有20个,希望大家喜欢
- StarUML---推荐一款UML工具(很好很强大)
- 【转】刚发现一个linux在线文档库。很好很强大。
- 很好很强大的Excel
- Ruby on rails开发从头来(四十七)- ActiveRecord基础(强大的find方法)
- SQL语句示例集2-很好很强大
- lua——很好很强大的脚本语言
- 很好很强大的vimrc(带注释版)