A resource management library for Ruby, an assistance to help you keep your resource (disk, memory) requirements healthy.
Reserve the amount of resources your application needs, and move forward accordingly.
You can stop allocating resources upon getting an exception indicating insufficient resources of any type.
require 'slotz'
class MyApp
Slotz::Reservation.provision(
self,
disk: 1 * 1_000_000_000, # bytes
memory: 5 * 1_000_000_000 #
)
end
my_app = MyApp.new
p my_app.available_slots
#=> 11
p my_app.available_slots_on_disk
#=> 1425
p my_app.available_slots_in_memory
#=> 11
p Slotz.utilization
#=> 0.08933773478082488 %versus:
require 'slotz'
class MyApp
Slotz::Reservation.provision(
self,
disk: 99 * 1_000_000_000, # bytes
memory: 50 * 1_000_000_000 #
)
end
my_app = MyApp.new
p my_app.available_slots
#=> 1
p my_app.available_slots_on_disk
#=> 13
p my_app.available_slots_in_memory
#=> 1
p Slotz.utilization
#=> 0.911408461062344In order to still allow for spawn/loader functionality to be accommodated, you can spawn or load
your file of interest accordingly, and still maintain the desired resource management.
This can be the file you wish to load:
p $options # Pre-set options.
# => {:execute=>false}
# => {:my=>:option, :ppid=>3158249, :tmpdir=>"/tmp", :execute=>true}
class Child
Slotz::Reservation.provision(
self,
disk: 1 * 1_000_000_000,
memory: 5 * 1_000_000_000
)
end
# Just load for the inside view. don't run anything, unless you've been instructed to.
return unless $execute
# Load everything to run.
# [...]require 'slotz'
loader = Slotz::Loader.new
loader.load( 'Child', "tmp/test2/child.rb", { my: :option } )