when using capistrano for a large amount of servers you get into
trouble when capistrano consumes all your memory and cpu resources.
Besides that it isn't very effective to start hundreds of threads.
I attach a simple patch for connections.rb which allows you to limit
the maximum number of parallel sessions by setting the task
option :maxsessions or by setting the enviroment variable
CAPMAXSESSIONS. Setting :maxsessions to 0 disables the limit.
Without any settings the number of parallel sessions is limited to 100
which at least can be handled by a typical server hardware.
For me this patch works without any negative side effects but I didn't
test all features of capistrano!
--- connections.rb 2008-01-28 12:39:10.000000000 +0100
+++ connections-maxsessions.rb 2008-01-28 12:45:17.000000000 +0100
@@ -1,5 +1,6 @@
require 'capistrano/gateway'
require 'capistrano/ssh'
+require 'enumerator'
module Capistrano
class Configuration
@@ -121,22 +122,30 @@
logger.trace "servers: #{servers.map { |s| s.host }.inspect}"
# establish connections to those servers, as necessary
- begin
- establish_connections_to(servers)
- rescue ConnectionError => error
- raise error unless task && task.continue_on_error?
- error.hosts.each do |h|
- servers.delete(h)
- failed!(h)
+ task.options[:maxsessions] = ENV['CAPMAXSESSIONS'] || 100 if
task.options[:maxsessions].nil?
+ task.options[:maxsessions] = servers.length if
task.options[:maxsessions] == 0
+ servers.each_slice(task.options[:maxsessions]) do |servers|
+ begin
+ establish_connections_to(servers)
+ rescue ConnectionError => error
+ raise error unless task && task.continue_on_error?
+ error.hosts.each do |h|
+ servers.delete(h)
+ failed!(h)
+ end
end
- end
- begin
- yield servers
- rescue RemoteError => error
- raise error unless task && task.continue_on_error?
- error.hosts.each { |h| failed!(h) }
- end
+ begin
+ yield servers
+ rescue RemoteError => error
+ raise error unless task && task.continue_on_error?
+ error.hosts.each { |h| failed!(h) }
+ end
+
+ # clear all sessions for this slice of servers
+ sessions.clear
+
+ end
end
private
--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---