Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3 Cli执行命令的速度真的很慢吗?_Ruby On Rails_Ruby_Command Line Interface_Execution_Performance - Fatal编程技术网

Ruby on rails Rails 3 Cli执行命令的速度真的很慢吗?

Ruby on rails Rails 3 Cli执行命令的速度真的很慢吗?,ruby-on-rails,ruby,command-line-interface,execution,performance,Ruby On Rails,Ruby,Command Line Interface,Execution,Performance,有人知道为什么我的rails 3.0.7 cli这么慢吗?当我运行rails s或rails g时,大约需要5秒钟,直到他真正执行命令为止 有什么建议吗?感谢更新:我将我的建议从rrails改为rails sh,因为前者支持REPL,这不是rrails的使用案例。此外,当与ruby环境变量结合使用时,补丁似乎可以提高性能,现在的答案中反映了这一点 一个可能的原因可能是,每当ruby代码中使用“require”时,它就会调用一些代码(更多详细信息)。在使用Rails进行开发时,我在开发箱中也遇到

有人知道为什么我的rails 3.0.7 cli这么慢吗?当我运行
rails s
rails g
时,大约需要5秒钟,直到他真正执行命令为止


有什么建议吗?感谢更新:

我将我的建议从rrails改为rails sh,因为前者支持REPL,这不是rrails的使用案例。此外,当与ruby环境变量结合使用时,补丁似乎可以提高性能,现在的答案中反映了这一点


一个可能的原因可能是,每当ruby代码中使用“require”时,它就会调用一些代码(更多详细信息)。在使用Rails进行开发时,我在开发箱中也遇到了这个问题(目前我在ruby 1.9.3p194上使用Rails 3.2.6)。开发环境在Ubuntu上运行,但这个问题可能发生在其他操作系统上,因为它基于解释器

虽然这个bug还没有修复,但我做了两件事来节省ruby CLI的时间。第一个是使用rails sh预加载,第二个是使用流行的ruby性能提升补丁来构建更快的MRI ruby

有两个库可以很好地预加载:和。两者都很好,但我将讨论rails sh,因为它在终端中为
rails console
和代码中的
binding.pry
/
调试器
等命令提供了REPL支持

设置rails-sh 我把它放在了我的开发组中,因为在那里我经常使用rails/rake命令,需要速度

group :development do
#...
  gem 'rails-sh'
end
然后安装它:

bundle install --binstubs=./bundler_stubs
(我使用binstubs来避免命令中的“bundle exec”,但这是可选的)

现在只需打开rails项目的备用终端并运行rails sh(如果需要,添加
bundle exec
):

现在您可以在该提示符中使用rake和rails命令

rails-sh(site)> rails s
$ rails s
=> Booting Thin
=> Rails 3.2.6 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.4.1 codename Chromeo)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
或者运行像db:test:prepare这样的rake任务:

rails-sh(site)> rake db:test:prepare
12.471001136sec
rails-sh(site)> 
但是它快吗?嗯,在我的机器上(一台具有8gig RAM的core i5笔记本电脑),rake db:test:prepare在rails sh命令(见上文)中花费了12.5秒,而在没有rails sh命令的情况下花费了34秒:

$ time rake db:test:prepare
real  0m34.796s
user  0m21.057s
sys 0m1.144s
$
22秒的区别是rails sh外部的rake命令必须在访问数据库之前加载rails环境,这是浪费,因为它没有改变。这同样适用于
rails
命令

补丁红宝石 MRI rubies的另一个解决方案是在ruby 1.9上安装一个流行的补丁(,railsexpress),并添加一些使用它的环境变量,该解决方案与预加载兼容,并在中建议

我在rvm安装上测试了falcon和railsexpress补丁(分别),并在这两种情况下获得了类似的性能

$rvm获取头部
$rvm清理源
$rvm安装ruby-1.9.3-p194--重新配置--命名猎鹰--补丁猎鹰--强制自动功能-j 3
$rvm使用ruby-1.9.3-p194-falcon
利用补丁

export RUBY\u HEAP\u MIN\u SLOTS=1000000
导出RUBY\u堆\u插槽\u增量=1000000
导出RUBY\u堆\u插槽\u增长系数=1
导出RUBY\u GC\u MALLOC\u LIMIT=100000000
导出RUBY\u堆\u自由\u最小值=500000

您可以跟踪rvm中哪些ruby可用的补丁程序。

您是否有可能使用ruby 1.9?那么这个问题在ruby trunk中已经“修复”了吗?还没有尝试trunk,但他们似乎已经发布了补丁程序来处理当前的ruby。调整答案以反映这一点。
$ time rake db:test:prepare
real  0m34.796s
user  0m21.057s
sys 0m1.144s
$