卡皮斯特拉诺很慢

时间:2012-01-18 08:41:11

标签: ruby-on-rails ruby-on-rails-3 capistrano

我不确定问题究竟在哪里,但Capistrano大约花了5分钟来部署一个几乎空的项目。

你能告诉我,我做错了什么或是不正常的?

我正在使用:

  • Capistrano 2.9.0
  • Rails 3.1.3
  • Github存储库
  • 服务器速度不太慢(4核,1 GB内存)
  • ngix,乘客

以下是我得到的输出: https://gist.github.com/1632009

Capfile

load 'deploy' if respond_to?(:namespace) # cap2 differentiator
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks

deploy.rb

# -*- encoding : utf-8 -*-
require "bundler/capistrano"

set :user, 'rubys'
set :domain, 'example.com'
set :application, 'EXAMPLE'

# adjust if you are using RVM, remove if you are not
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :rvm_ruby_string, '1.9.2'
#set :rvm_type, :user

# file paths
set :repository,  "git@github.com:GITHUBREPO/ashop.git"
set :deploy_to, "/apps/#{application}"

# using a local git repository on the server you are deploying to.
set :deploy_via, :remote_cache
set :copy_exclude, [ '.git' ]


# distribute your applications across servers (the instructions below put them
# all on the same server, defined above as 'domain', adjust as necessary)
role :app, domain
role :web, domain
role :db, domain, :primary => true


set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, false
set :use_sudo, false
set :rails_env, :production

namespace :deploy do
  desc "cause Passenger to initiate a restart"
  task :restart do
    run "touch #{current_path}/tmp/restart.txt"
  end
end

修改

1 个答案:

答案 0 :(得分:1)

Capistrano可能因为一系列原因而变慢。一个是它为您的deploy.rb文件中的每个run打开一个新的远程shell到您的服务器。

这可以通过使用ssh主通道进行一些修改,这将导致capistrano实际重用ssh连接,这意味着网络开销减少。

这是一篇关于ruby部署的文章,其中提到了ssh主渠道:http://alexyoung.org/2011/05/17/deployment/

另一个原因是它将整个代码库复制到每个部署的新目录。

使用git时并不是绝对必要的,github有一篇关于如何“修复”这篇内容的精彩文章:https://github.com/blog/470-deployment-script-spring-cleaning