Class: Griffin::Interceptors::Server::WorkerKillerInterceptor
- Inherits:
-
GRPC::ServerInterceptor
- Object
- GRPC::ServerInterceptor
- Griffin::Interceptors::Server::WorkerKillerInterceptor
- Defined in:
- lib/griffin/interceptors/server/worker_killer_interceptor.rb
Instance Method Summary collapse
-
#initialize(memory_limit_min: 1024**3, memory_limit_max: 2 * (1024**3), check_cycle: 16) ⇒ WorkerKillerInterceptor
constructor
A new instance of WorkerKillerInterceptor.
- #request_response ⇒ Object (also: #server_streamer, #client_streamer, #bidi_streamer)
Constructor Details
#initialize(memory_limit_min: 1024**3, memory_limit_max: 2 * (1024**3), check_cycle: 16) ⇒ WorkerKillerInterceptor
Returns a new instance of WorkerKillerInterceptor.
9 10 11 12 13 14 15 16 |
# File 'lib/griffin/interceptors/server/worker_killer_interceptor.rb', line 9 def initialize(memory_limit_min: 1024**3, memory_limit_max: 2 * (1024**3), check_cycle: 16) @worker_memory_limit_max = memory_limit_max @worker_memory_limit_min = memory_limit_min @worker_check_cycle = check_cycle @worker_memory_limit = @worker_memory_limit_min + rand(@worker_memory_limit_max - @worker_memory_limit_min + 1) @worker_check_count = 0 @sent_signals = false end |
Instance Method Details
#request_response ⇒ Object Also known as: server_streamer, client_streamer, bidi_streamer
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/griffin/interceptors/server/worker_killer_interceptor.rb', line 18 def request_response(*) yield.tap do break if @sent_signals @worker_process_start ||= Time.now @worker_check_count += 1 if (@worker_check_count % @worker_check_cycle) == 0 rss = GetProcessMem.new.bytes if rss > @worker_memory_limit Griffin.logger.warn("Worker (pid: #{Process.pid}) exceeds memory limit (#{rss.to_i} bytes > #{@worker_memory_limit} bytes)") send_restart_signal(@worker_process_start) end @worker_check_count = 0 end end end |