Skip to content

Commit

Permalink
now you can disable the logic (both maxreq and maxmemory) by configur…
Browse files Browse the repository at this point in the history
…ation.

fixes #11. thanks @scottshea for suggesting this problem.
  • Loading branch information
kzk committed Feb 3, 2013
1 parent 807893b commit d7ebd70
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/unicorn/worker_killer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def self.new(app, memory_limit_min = (1024**3), memory_limit_max = (2*(1024**3))
end

def process_client(client)
@_worker_process_start ||= Time.now
@_worker_memory_limit ||= @_worker_memory_limit_min + Random.rand(@_worker_memory_limit_max-@_worker_memory_limit_min+1)
super(client) # Unicorn::HttpServer#process_client
return if @_worker_memory_limit_min == 0 && @_worker_memory_limit_max == 0

@_worker_process_start ||= Time.now
@_worker_memory_limit ||= @_worker_memory_limit_min + Random.rand(@_worker_memory_limit_max-@_worker_memory_limit_min+1)
@_worker_check_count += 1
if @_worker_check_count % @_worker_check_cycle == 0
rss = _worker_rss()
Expand Down Expand Up @@ -103,11 +104,12 @@ def self.new(app, max_requests_min = 3072, max_requests_max = 4096)
end

def process_client(client)
super(client) # Unicorn::HttpServer#process_client
return if @_worker_max_requests_min == 0 && @_worker_max_requests_max == 0

@_worker_process_start ||= Time.now
@_worker_cur_requests ||= @_worker_max_requests_min + Random.rand(@_worker_max_requests_max-@_worker_max_requests_min+1)
@_worker_max_requests ||= @_worker_cur_requests
super(client) # Unicorn::HttpServer#process_client

if (@_worker_cur_requests -= 1) <= 0
logger.warn "#{self}: worker (pid: #{Process.pid}) exceeds max number of requests (limit: #{@_worker_max_requests})"
Unicorn::WorkerKiller.kill_self(logger, @_worker_process_start)
Expand Down

0 comments on commit d7ebd70

Please sign in to comment.