lib/sneakers/workergroup.rb in sneakers-1.0.4 vs lib/sneakers/workergroup.rb in sneakers-1.1.0
- old
+ new
@@ -17,19 +17,23 @@
end
def run
after_fork
- @workers = config[:worker_classes].map{|w| w.new }
+ # Allocate single thread pool if share_threads is set. This improves load balancing
+ # when used with many workers.
+ pool = config[:share_threads] ? Thread.pool(config[:threads]) : nil
+
+ @workers = config[:worker_classes].map{|w| w.new(nil, pool) }
# if more than one worker this should be per worker
# accumulate clients and consumers as well
@workers.each do |worker|
worker.run
end
# end per worker
#
- until @stop_flag.wait_for_set(10.0)
+ until @stop_flag.wait_for_set(Sneakers::CONFIG[:amqp_heartbeat])
Sneakers.logger.debug("Heartbeat: running threads [#{Thread.list.count}]")
# report aggregated stats?
end
end
@@ -42,6 +46,5 @@
@stop_flag.set!
end
end
end
-