我最近尝试获取应用的strace
样本。我注意到的一点是,当ruby尝试需要一个文件时,它实际上会尝试在很多地方检查文件是否存在。例如,这是加载sprockets/processing
:
open("/bundle/ruby/2.1.0/gems/excon-0.38.0/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/eventmachine-1.0.3/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/eventmachine-1.0.3/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/draper-1.3.1/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/request_store-1.0.8/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/devise-async-0.9.0/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/warden-1.2.3/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/thread_safe-0.3.3/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/orm_adapter-0.5.0/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/delayed_job_active_record-4.0.0/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/delayed_job-4.0.0/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/dalli-2.7.0/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/daemons-rails-1.2.1/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/daemons-1.1.9/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/cube-ruby-0.0.3/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/cube-evaluator-0.0.1/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/bundle/ruby/2.1.0/gems/css_parser-1.3.5/lib/sprockets/processing.rb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
显然ruby / rails会检查每个目录,以找到请求文件的正确位置。我认为这是非常低效的。有没有办法改善这个?