Class: PumaWorkerKiller::PumaMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/puma_worker_killer/puma_memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(master = nil) ⇒ PumaMemory

Returns a new instance of PumaMemory.



5
6
7
8
# File 'lib/puma_worker_killer/puma_memory.rb', line 5

def initialize(master = nil)
  @master = master || get_master
  @workers = nil
end

Instance Attribute Details

#masterObject (readonly)

Returns the value of attribute master.



10
11
12
# File 'lib/puma_worker_killer/puma_memory.rb', line 10

def master
  @master
end

Instance Method Details

#get_total(workers = set_workers) ⇒ Object Also known as: get_total_memory

Will refresh @workers



53
54
55
56
57
# File 'lib/puma_worker_killer/puma_memory.rb', line 53

def get_total(workers = set_workers)
  master_memory = GetProcessMem.new(Process.pid).mb
  worker_memory = workers.values.inject(:+) || 0
  worker_memory + master_memory
end

#largest_workerObject



42
43
44
45
# File 'lib/puma_worker_killer/puma_memory.rb', line 42

def largest_worker
  largest_worker, = workers.to_a.last
  largest_worker
end

#largest_worker_memoryObject



47
48
49
50
# File 'lib/puma_worker_killer/puma_memory.rb', line 47

def largest_worker_memory
  _, largest_memory_used = workers.to_a.last
  largest_memory_used
end

#running?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/puma_worker_killer/puma_memory.rb', line 28

def running?
  @master && workers.any?
end

#sizeObject



12
13
14
# File 'lib/puma_worker_killer/puma_memory.rb', line 12

def size
  workers.size
end

#smallest_workerObject



32
33
34
35
# File 'lib/puma_worker_killer/puma_memory.rb', line 32

def smallest_worker
  smallest, = workers.to_a.first
  smallest
end

#smallest_worker_memoryObject



37
38
39
40
# File 'lib/puma_worker_killer/puma_memory.rb', line 37

def smallest_worker_memory
  _, smallest_mem = workers.to_a.first
  smallest_mem
end

#term_largest_workerObject



20
21
22
# File 'lib/puma_worker_killer/puma_memory.rb', line 20

def term_largest_worker
  largest_worker.term
end

#term_worker(worker) ⇒ Object



16
17
18
# File 'lib/puma_worker_killer/puma_memory.rb', line 16

def term_worker(worker)
  worker.term
end

#workersObject



60
61
62
# File 'lib/puma_worker_killer/puma_memory.rb', line 60

def workers
  @workers || set_workers
end

#workers_stopped?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/puma_worker_killer/puma_memory.rb', line 24

def workers_stopped?
  !running?
end