Class: Capelinhos::Processor
- Inherits:
-
Object
- Object
- Capelinhos::Processor
- Defined in:
- lib/capelinhos/processor.rb
Instance Method Summary collapse
-
#initialize(memory_threshold:, process_limit:) ⇒ Processor
constructor
A new instance of Processor.
- #kill_memory_hogs! ⇒ Object
Constructor Details
#initialize(memory_threshold:, process_limit:) ⇒ Processor
Returns a new instance of Processor.
7 8 9 10 |
# File 'lib/capelinhos/processor.rb', line 7 def initialize(memory_threshold:, process_limit:) @memory_threshold = memory_threshold @process_limit = process_limit end |
Instance Method Details
#kill_memory_hogs! ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/capelinhos/processor.rb', line 12 def kill_memory_hogs! processes_killed = 0 stats = AdminTools::MemoryStats.new processes = stats.passenger_processes if !supports_private_dirty_rss?(processes) puts "This system doesn't support private dirty RSS. Falling back to RSS" end rss_type = supports_private_dirty_rss?(processes) ? :private_dirty_rss : :rss processes.each do |process| if process.name.include?('RubyApp') rss_megabytes = process.send(rss_type) / 1024 if rss_megabytes > @memory_threshold shutdown_process(process.pid) processes_killed += 1 end if processes_killed >= @process_limit break end end end end |