Class: Cuboid::System::Slots
Instance Method Summary collapse
-
#available ⇒ Integer
Amount of new scans that can be safely run in parallel, currently.
-
#available_auto ⇒ Integer
Amount of new scans that can be safely run in parallel, currently.
-
#available_in_cpu ⇒ Integer
Amount of CPU cores that are available.
-
#available_in_disk ⇒ Integer
Amount of scans we can fit into the available disk space.
-
#available_in_memory ⇒ Integer
Amount of scans we can fit into the available memory.
- #disk_space ⇒ Object
-
#initialize(system) ⇒ Slots
constructor
A new instance of Slots.
-
#memory_size ⇒ Fixnum
Amount of memory (in bytes) to allocate to each scan.
-
#remaining_disk_space_for(pid) ⇒ Integer
Remaining disk space for the scan, in bytes.
-
#remaining_memory_for(pid) ⇒ Integer
Remaining memory for the scan, in bytes.
- #reset ⇒ Object
-
#total ⇒ Integer
Amount of scans that can be safely run in parallel, in total.
-
#unallocated_disk_space ⇒ Integer
Amount of disk space (in bytes) available for future scans.
-
#unallocated_memory ⇒ Integer
Amount of memory (in bytes) available for future scans.
- #use(pid) ⇒ Object
-
#used ⇒ Integer
Amount of instances that are currently alive.
Constructor Details
#initialize(system) ⇒ Slots
6 7 8 9 |
# File 'lib/cuboid/system/slots.rb', line 6 def initialize( system ) @system = system @pids = Set.new end |
Instance Method Details
#available ⇒ Integer
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cuboid/system/slots.rb', line 23 def available # Manual mode, user gave us a value. if (max_slots = Options.system.max_slots) max_slots - used # Auto-mode, pick the safest restriction, RAM vs CPU. else available_auto end end |
#available_auto ⇒ Integer
37 38 39 |
# File 'lib/cuboid/system/slots.rb', line 37 def available_auto [ available_in_memory, available_in_cpu, available_in_disk ].min end |
#available_in_cpu ⇒ Integer
69 70 71 |
# File 'lib/cuboid/system/slots.rb', line 69 def available_in_cpu @system.cpu_count - used end |
#available_in_disk ⇒ Integer
78 79 80 81 |
# File 'lib/cuboid/system/slots.rb', line 78 def available_in_disk return Float::INFINITY if disk_space == 0 (unallocated_disk_space / disk_space).to_i end |
#available_in_memory ⇒ Integer
59 60 61 62 |
# File 'lib/cuboid/system/slots.rb', line 59 def available_in_memory return Float::INFINITY if memory_size == 0 (unallocated_memory / memory_size).to_i end |
#disk_space ⇒ Object
129 130 131 132 |
# File 'lib/cuboid/system/slots.rb', line 129 def disk_space return 0 if !Cuboid::Application.application Cuboid::Application.application.max_disk.to_i end |
#memory_size ⇒ Fixnum
136 137 138 139 |
# File 'lib/cuboid/system/slots.rb', line 136 def memory_size return 0 if !Cuboid::Application.application Cuboid::Application.application.max_memory.to_i end |
#remaining_disk_space_for(pid) ⇒ Integer
110 111 112 |
# File 'lib/cuboid/system/slots.rb', line 110 def remaining_disk_space_for( pid ) [disk_space - @system.disk_space_for_process( pid ), 0].max end |
#remaining_memory_for(pid) ⇒ Integer
87 88 89 |
# File 'lib/cuboid/system/slots.rb', line 87 def remaining_memory_for( pid ) [memory_size - @system.memory_for_process_group( pid ), 0].max end |
#reset ⇒ Object
11 12 13 |
# File 'lib/cuboid/system/slots.rb', line 11 def reset @pids.clear end |
#total ⇒ Integer
50 51 52 |
# File 'lib/cuboid/system/slots.rb', line 50 def total used + available end |
#unallocated_disk_space ⇒ Integer
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/cuboid/system/slots.rb', line 116 def unallocated_disk_space # Available space right now. available_space = @system.disk_space_free # Remove allocated space to figure out how much we can really spare. @pids.each do |pid| # Mark the remaining allocated space as unavailable. available_space -= remaining_disk_space_for( pid ) end available_space end |
#unallocated_memory ⇒ Integer
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/cuboid/system/slots.rb', line 93 def unallocated_memory # Available memory right now. available_mem = @system.memory_free # Remove allocated memory to figure out how much we can really spare. @pids.each do |pid| # Mark the remaining allocated memory as unavailable. available_mem -= remaining_memory_for( pid ) end available_mem end |
#use(pid) ⇒ Object
15 16 17 18 |
# File 'lib/cuboid/system/slots.rb', line 15 def use( pid ) @pids << pid pid end |
#used ⇒ Integer
43 44 45 46 |
# File 'lib/cuboid/system/slots.rb', line 43 def used @pids.select! { |pid| Processes::Manager.alive? pid } @pids.size end |