lib/bixby-common/util/thread_pool.rb in bixby-common-0.6.0 vs lib/bixby-common/util/thread_pool.rb in bixby-common-0.6.1
- old
+ new
@@ -27,10 +27,11 @@
expand(@min_size)
end
def enqueue(command, block=nil)
+ logger.debug { "enqueue new task: #{command}" }
@input_queue.push(Task.new(command, block))
if command == :perform then
grow_pool
end
nil
@@ -102,11 +103,11 @@
end
end
def expand(count)
@lock.synchronize do
- # logger.debug "expanding by #{count} threads (from #{@size})"
+ logger.debug "expanding by #{count} threads (from #{@size})"
count.times do
create_worker
end
end
@@ -157,11 +158,11 @@
private
def create_worker
@lock.synchronize do
- # logger.debug "spawning new worker thread"
+ logger.debug "spawning new worker thread"
exit_handler = lambda { |worker, reason|
@lock.synchronize do
if reason == :exception or (reason == :timeout && @size > @min_size) then
@size -= 1
@@ -178,15 +179,17 @@
end
# Grow the pool by one if we have more jobs than idle workers
def grow_pool
@lock.synchronize do
- # logger.debug { "busy: #{num_working}; idle: #{num_idle}" }
+ logger.debug { "jobs: #{num_jobs}; busy: #{num_working}; idle: #{num_idle}" }
if @size < @max_size && num_jobs > 0 && num_jobs > num_idle then
space = @max_size-@size
jobs = num_jobs-num_idle
needed = space < jobs ? space : jobs
expand(needed)
+ else
+ logger.debug "NOT growing the pool!"
end
end
nil
end