[英]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.