2013-10-25 118 views
0

「耙資產:預編譯」和「帽​​部署」每當我打電話時(通常多於一個小時)消耗非常高的時間量。有時部署掛在一起。 我使用Rails 3.2.13,Ruby 1.9.3,OSX和Backbone的Chaplin Framework for frontend。 如何加快資產預編譯和部署任務以及會導致此類凍結的原因?Capistrano部署和資產:預編譯太慢

我deploy.rb配置:

# -*- encoding : utf-8 -*- 
require 'bundler/capistrano' 
load 'deploy/assets' 

set :application, "eyelashes" 
set :rails_env, "production" 

set :repository, "[email protected]:eyelasher/repo.git" 
set :scm, :git 
set :deploy_via, :checkout 
set :ssh_options, { :forward_agent => true } 
default_run_options[:pty] = true 


server "75.223.145.3", :app, :web, :db, :primary => true 

set :bundle_without, [:test] 

set :user, 'deployer' 
set :deploy_to, "/home/deployer/eyelasher" 
set :branch, "master" unless exists?(:branch) 
set :use_sudo, false 

set :rvm_type, :user 
set :rvm_ruby_string, :local 
set :deploy_via, :checkout 
before 'deploy:setup', 'rvm:create_gemset' 

set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb" 
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid" 

after "deploy", "deploy:migrate" 
after "deploy", "deploy:cleanup" 

require 'rvm/capistrano' 
require 'thinking_sphinx/deploy/capistrano' 

#after 'deploy:update_code', :roles => :app do 
    #run "rm -f #{current_release}/config/database.yml" 
    #run "ln -s #{deploy_to}/shared/config/database.yml #{current_release}/config/database.yml" 
#end 

namespace :deploy do 
    task :restart do 
    run "if [ -f #{unicorn_pid} ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn -C#{unicorn_conf} -E #{rails_env} -D; fi" 
    end 
    task :start do 
    run "cd #{deploy_to}/current && bundle exec unicorn -C#{unicorn_conf} -E #{rails_env} -D;" 
    end 
    task :stop do 
    run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi" 
    end 

end 


# Thinking Sphinx typing shortcuts 
namespace :ts do 
    task :conf do 
    thinking_sphinx.configure 
    end 
    task :in do 
    thinking_sphinx.index 
    end 
    task :start do 
    thinking_sphinx.start 
    end 
    task :stop do 
    thinking_sphinx.stop 
    end 
    task :restart do 
    thinking_sphinx.restart 
    end 
    task :rebuild do 
    thinking_sphinx.rebuild 
    end 
end 

# http://github.com/jamis/capistrano/blob/master/lib/capistrano/recipes/deploy.rb 
# :default -> update, restart 
# :update -> update_code, symlink 
namespace :deploy do 
    desc "Link up Sphinx's indexes." 
    task :symlink_sphinx_indexes, :roles => [:app] do 
    run "ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx" 
    end 

    task :activate_sphinx, :roles => [:app] do 
    symlink_sphinx_indexes 
    thinking_sphinx.configure 
    #thinking_sphinx.stop 
    #thinking_sphinx.start 
    end 

    task :copy_images do 
    run "cp -R #{shared_path}/public/images #{release_path}/public/images" 
    end 

    before 'deploy:update_code', 'thinking_sphinx:stop' 
    after 'deploy:update_code', 'deploy:activate_sphinx' 
    after 'deploy:update_code', 'deploy:copy_images' 

end 

也許我能以某種方式通過在配置更改部署加速比?

回答

0

如果您正在部署到內存受限的VPS,這聽起來似乎合理。我建議在更快的機器上預編譯資產並將它們檢入到存儲庫中。

有許多寶石和軟件包可以加快資產預編譯的速度,但是在您的情況下,這可能會讓事情變得更糟!

+0

感謝您的回覆。但是,我的Leaseweb VDS速度非常快。 –

+0

*速度*沒有太大的區別!它主要是內存約束。您可能會嘗試刪除「初始化預編譯」。它會導致rails爲每個要重新編譯的文件啓動整個框架。 –

+0

我在生產配置中設置了initialize_on_precompile = false,但仍然很慢。 –

相關問題