简体   繁体   English

Ruby 1.9.3,Rails 3.2.12,OSX Lion-引导命令行脚本的Rails缓慢

[英]Ruby 1.9.3, Rails 3.2.12, OSX Lion - bootstrapping Rails for command-line scripts slow

Bootstrapping Rails in command-line scripts takes a long time (2.5+ seconds), for example: 在命令行脚本中引导Rails需要很长时间(2.5+秒),例如:

timer = Time.now  
ENV["RAILS_ENV"] ||= "development"  
require File.expand_path('../../config/application', __FILE__)  
Rails.application.require_environment!  
puts "Init complete in #{Time.now - timer} sec"  
# -> Init complete in 2.621531 sec  

Am I missing something ? 我想念什么吗? If not, do I really need to bootstrap everything to get access to the models ? 如果不是,我真的需要引导所有内容以访问模型吗?

I don't have a lot of experience with this, but perhaps you should take a look at trimming down the number of libraries that are required in application.rb : 我没有很多经验,但是也许您应该看看如何减少application.rb所需的库数量:

# require 'rails/all' # remove this and only require what you need
require 'activerecord/railtie' # this may be all you need

Additionally, take a look at the gems you are loading and see if any of them are taking an inordinate amount of time . 此外,请查看您正在加载的宝石,并查看它们是否花费了过多的时间 If a particular gem is slowing down boot time, simply add: 如果特定的宝石正在减慢启动时间,只需添加:

# you will need to explicitly load the gem when needed,
# but it won't be required at boot time 
gem some_gem, :require => false

You could create a special environment that you run the script in and customize the boot process for that environment. 您可以创建一个运行脚本的特殊环境,并为该环境自定义启动过程。

You should profile that block of code and see where most of the time is spent. 您应该分析该代码块并查看大部分时间在哪里。

What exactly are you trying to get out of booting rails? 您到底想摆脱引导轨是什么? Access to the models? 访问模型? the underlying data? 基础数据? Perhaps there's an alternate approach than booting all of rails. 也许除了引导所有的导轨以外,还有另一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 安装libCurl-ruby 1.9.3 .. rails 3.2.12 .. Windows - Installing libCurl - ruby 1.9.3 .. rails 3.2.12 .. Windows 慢资产红宝石1.9.3,macos,rails 3.2 - Slow assets ruby 1.9.3, macos, rails 3.2 从Ruby命令行应用程序将文件上传到Rails应用程序 - Upload a file to a Rails Application from a Ruby command-line application 试图在OSX Mountain Lion上安装Ruby / Rails - Trying to get Ruby/Rails installed on OSX Mountain Lion Ruby on Rails无法在OSX Mountian Lion上启动服务器 - ruby on rails can't launch server on osx mountian lion Ruby版本的Rails和activesupport-3.2.12的困难 - Difficulties with Ruby version for Rails and activesupport-3.2.12 测试在我的Ubuntu pc上运行,但不在我的Mac OS X Lion 10.7.3,Ruby 1.9.3,Rails 3.2.1上运行 - Tests are running on my Ubuntu pc, but not on my Mac OS X Lion 10.7.3, Ruby 1.9.3, Rails 3.2.1 捆绑安装将无法使用Ruby 1.9.3,Rails3和Mac Mountain Lion安装mysql2 gem - Bundle Install wont install mysql2 gem with Ruby 1.9.3, Rails3 and Mac Mountain Lion 在Mac OS X Lion上安装Ruby 1.9.3和Rails 3.1.3时出错 - Error while installing Ruby 1.9.3 and Rails 3.1.3 on Mac OS X Lion Ruby on Rails和Mac OS Lion超级慢! 为什么? - Ruby on Rails and Mac OS Lion super slow! Why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM