Class: Chore::Strategy::WorkerKiller
- Inherits:
-
Object
- Object
- Chore::Strategy::WorkerKiller
- Defined in:
- lib/chore/strategies/worker/helpers/worker_killer.rb
Overview
:nodoc:
Instance Method Summary collapse
- #check_memory ⇒ Object
- #check_requests ⇒ Object
-
#initialize ⇒ WorkerKiller
constructor
A new instance of WorkerKiller.
Constructor Details
#initialize ⇒ WorkerKiller
Returns a new instance of WorkerKiller.
6 7 8 9 10 11 12 |
# File 'lib/chore/strategies/worker/helpers/worker_killer.rb', line 6 def initialize @memory_limit = Chore.config.memory_limit_bytes @request_limit = Chore.config.request_limit @check_cycle = Chore.config.worker_check_cycle || 16 @check_count = 0 @current_requests = 0 end |
Instance Method Details
#check_memory ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/chore/strategies/worker/helpers/worker_killer.rb', line 14 def check_memory return if @memory_limit.nil? || (@memory_limit == 0) @check_count += 1 if @check_count == @check_cycle rss = GetProcessMem.new.bytes.to_i if rss > @memory_limit Chore.logger.info "WK: (pid: #{Process.pid}) exceeded memory limit (#{rss.to_i} bytes > #{@memory_limit} bytes)" Chore.run_hooks_for(:worker_mem_kill) exit(true) end @check_count = 0 end end |
#check_requests ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/chore/strategies/worker/helpers/worker_killer.rb', line 29 def check_requests return if @request_limit.nil? || (@request_limit == 0) if (@current_requests += 1) >= @request_limit Chore.logger.info "WK: (pid: #{Process.pid}) exceeded max number of requests (limit: #{@request_limit})" Chore.run_hooks_for(:worker_req_kill) exit(true) end end |