only run ssh runners if there are files to run remotely, and fix kernel.select to work even better

This commit is contained in:
John Bintz 2011-09-25 10:39:29 -04:00
parent 5ef29ee43e
commit b25fe51eda
2 changed files with 15 additions and 2 deletions

View File

@ -72,6 +72,18 @@ module Hydra #:nodoc:
# default is one worker that is configured to use a pipe with one runner
worker_cfg = opts.fetch('workers') { [ { 'type' => 'local', 'runners' => 1} ] }
# if the number of files to run is equal to or less than the count of local
# runners, don't even bother with retmote workers.
locals, sshes = worker_cfg.partition { |l| l['type'] == 'local' }
if !locals.empty?
if @files.length <= locals.first['runners']
sshes = []
end
end
worker_cfg = locals + sshes
trace "Initialized"
trace " Files: (#{@files.inspect})"
trace " Workers: (#{worker_cfg.inspect})"

View File

@ -11,13 +11,14 @@ module Hydra #:nodoc:
while true
begin
raise IOError unless @reader
if !@timeout || (result = Kernel.select([@reader], [], [], @timeout))
message = nil
if result = Kernel.select([@reader], [], [], @timeout)
message = @reader.gets
end
return Message.build(:class => Hydra::Messages::Master::Shutdown) if result == nil
return nil unless message
return Message.build(eval(message.chomp))
rescue SyntaxError, NameError
rescue SyntaxError, NameError, Errno::EBADF
# uncomment to help catch remote errors by seeing all traffic
#$stderr.write "Not a message: [#{message.inspect}]\n"
end