Revamp the THREADS handling for aux run_host() and run_batch(). THREADS is

supposed to be the number of concurrent threads; however, what's been happening
is just the firing off of THREADS threads and then simply waiting for them all
to finish before doing another round.

Now it tries to keep new threads coming when possible.  It's not exactly smart,
but should usually beat the previous method (when using multiple threads) and
should never be any worse.

Here's the relevant code comment:

# Assume that the oldest thread will be one of the
# first to finish and wait for it.  After that's
# done, remove any finished threads from the list
# and continue on.  This will open up at least one
# spot for a new thread



git-svn-id: file:///home/svn/framework3/trunk@6809 4d416f70-5f16-0410-b530-b9f4589650da
unstable
kris 2009-07-16 02:27:18 +00:00
parent 4b9785e1b7
commit 8d6e48bc0b
1 changed files with 21 additions and 13 deletions

View File

@ -63,9 +63,9 @@ def run
if (self.respond_to?('run_host'))
ar = Rex::Socket::RangeWalker.new(datastore['RHOSTS'])
while (true)
tl = []
tl = []
while (true)
# Spawn threads for each host
while (tl.length < threads_max)
ip = ar.next_ip
@ -75,7 +75,7 @@ def run
targ = tip
nmod = self.replicant
nmod.datastore['RHOST'] = targ
begin
nmod.run_host(targ)
rescue ::Interrupt
@ -92,9 +92,14 @@ def run
if(tl.length == 0)
break
end
# Wait for the threads
tl.each { |t| t.join }
# Assume that the oldest thread will be one of the
# first to finish and wait for it. After that's
# done, remove any finished threads from the list
# and continue on. This will open up at least one
# spot for a new thread
tl.first.join
tl.delete_if { |t| not t.alive? }
end
return
@ -111,10 +116,9 @@ def run
ar = Rex::Socket::RangeWalker.new(datastore['RHOSTS'])
tl = []
while(true)
tl = []
nohosts = false
while (tl.length < threads_max)
@ -130,7 +134,6 @@ def run
batch << ip
end
# Create a thread for each batch
if (batch.length > 0)
tl << Thread.new(batch) do |bat|
@ -152,14 +155,19 @@ def run
break
end
end
# Wait for the threads
tl.each { |t| t.join }
# Exit if there are no more pending threads
if (tl.length == 0)
break
end
# Assume that the oldest thread will be one of the
# first to finish and wait for it. After that's
# done, remove any finished threads from the list
# and continue on. This will open up at least one
# spot for a new thread
tl.first.join
tl.delete_if { |t| not t.alive? }
end
return