Sha256: 9aa37e86fd2157ed291300f3b8eaabbda7566a82d31f57b747686bc6ae2f4d1f

Contents?: true

Size: 1.26 KB

Versions: 11

Compression:

Stored size: 1.26 KB

Contents

module Sneakers
  module WorkerGroup
    @workers = []

    def initialize
      @stop_flag = ServerEngine::BlockingFlag.new
    end

    def before_fork
      fbefore = Sneakers::CONFIG[:hooks][:before_fork]
      fbefore.call if fbefore
    end

    def after_fork # note! this is not Serverengine#after_start, this is ours!
      fafter = Sneakers::CONFIG[:hooks][:after_fork]
      fafter.call if fafter
    end

    def run
      after_fork

      # 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(Sneakers::CONFIG[:amqp_heartbeat])
        Sneakers.logger.debug("Heartbeat: running threads [#{Thread.list.count}]")
        # report aggregated stats?
      end

    end

    def stop
      Sneakers.logger.info("Shutting down workers")
      @workers.each do |worker|
        worker.stop
      end
      @stop_flag.set!
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sneakers-2.3.5 lib/sneakers/workergroup.rb
sneakers-2.3.4 lib/sneakers/workergroup.rb
sneakers-2.3.2 lib/sneakers/workergroup.rb
sneakers-2.3.1 lib/sneakers/workergroup.rb
sneakers-2.3.0 lib/sneakers/workergroup.rb
sneakers-2.2.1 lib/sneakers/workergroup.rb
sneakers-2.2.0 lib/sneakers/workergroup.rb
sneakers-2.1.0 lib/sneakers/workergroup.rb
sneakers-1.1.2 lib/sneakers/workergroup.rb
sneakers-1.1.1 lib/sneakers/workergroup.rb
sneakers-1.1.0 lib/sneakers/workergroup.rb