Skip to content

Instantly share code, notes, and snippets.

@xiangzhuyuan
Last active March 15, 2016 07:14
Show Gist options
  • Save xiangzhuyuan/230d67f1cf09cda03de5 to your computer and use it in GitHub Desktop.
Save xiangzhuyuan/230d67f1cf09cda03de5 to your computer and use it in GitHub Desktop.
available thread counts?
#
# Returns the number of threads waiting on the queue.
#
def num_waiting
@num_waiting
end
end
# when init EM env, there is a thread pool would be inited
# with default configutation. the `num_waiting` would be set as that value
#/usr/local/var/rbenv/versions/2.0.0-p598/lib/ruby/gems/2.0.0/gems/eventmachine-1.0.7/lib/em/pool.rb:106
# A peek at the number of enqueued jobs waiting for resources #此处的` resources` 是指?
def num_waiting
@resources.num_waiting
end
@xiangzhuyuan
Copy link
Author

image

@xiangzhuyuan
Copy link
Author

      unless EM.defers_finished?
        wait_count     = 0
        error_occurred = false
        binding.pry
        while EM.threadqueue.num_waiting == 0
          if (wait_count % MallConf.batch.em_thread.monitor.wait_count.display_frequency) == 0
            Rails.logger.info "All threads are busy. wait_count=#{wait_count}"
            if !error_occurred && (wait_count >= error_threshold)
              error_occurred = true
              Rails.logger.error "Threads are waiting long time. It may need to restart. wait_count=#{wait_count}"
            end
          end
          sleep 1
          wait_count += 1
        end

        # use error log level so that RAMEN send an alert mail
        Rails.logger.error "Threads start working. It was a false alarm. wait_count=#{wait_count}" if error_occurred
      end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment