Class: Experiment::WorkServer
- Inherits:
-
Object
- Object
- Experiment::WorkServer
- Defined in:
- lib/experiment/work_server.rb
Overview
This class is responsible for disrtibuting work and instantiating experimental conditions according to available resources
Instance Method Summary collapse
- #as_class_name(str) ⇒ Object
- #experiment(num) ⇒ Object
-
#initialize(experiments, options, ip = "localhost") ⇒ WorkServer
constructor
A new instance of WorkServer.
- #instance(num) ⇒ Object
-
#new_item ⇒ Object
Workers call this method and recieve a new work object incrementally.
-
#notify ⇒ Object
accessor for the remote notification service.
- #ready? ⇒ Boolean deprecated Deprecated.
Constructor Details
#initialize(experiments, options, ip = "localhost") ⇒ WorkServer
Returns a new instance of WorkServer.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/experiment/work_server.rb', line 7 def initialize(experiments, , ip = "localhost") uri="druby://#{ip}:8787" # The object that handles requests on the server front_object = self #$SAFE = 1 # disable eval() and friends DRb.start_service(uri, front_object) @experiments = experiments @started = @experiments.map { |e| false } @done = @started @options = @experiment_instances = [] DRb.thread.join end |
Instance Method Details
#as_class_name(str) ⇒ Object
68 69 70 |
# File 'lib/experiment/work_server.rb', line 68 def as_class_name(str) str.split(/[\_\-]+/).map(&:capitalize).join end |
#experiment(num) ⇒ Object
60 61 62 |
# File 'lib/experiment/work_server.rb', line 60 def experiment(num) @experiments[num] end |
#instance(num) ⇒ Object
64 65 66 |
# File 'lib/experiment/work_server.rb', line 64 def instance(num) @experiment_instances[num] end |
#new_item ⇒ Object
Workers call this method and recieve a new work object incrementally
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/experiment/work_server.rb', line 28 def new_item @experiments.each_with_index do |e, i| if @experiment_instances[i].nil? exp = @experiments[i] require "./experiments/#{exp}/#{exp}" cla = eval(as_class_name(exp)) experiment = cla.new :master, exp, @options if experiment.respond_to? :master_sub_experiments subs = experiment.master_sub_experiments @options.cv @experiments += subs.map { exp } @experiment_instances += subs return i + 1 else experiment.run! @options.cv @experiment_instances[i] = experiment return i end elsif !@experiment_instances[i].distribution_done? return i end end DRb.stop_service if @experiment_instances.all? {|a| a.done? } false end |
#notify ⇒ Object
accessor for the remote notification service
55 56 57 |
# File 'lib/experiment/work_server.rb', line 55 def notify Notify end |
#ready? ⇒ Boolean
Deprecated.
23 24 25 |
# File 'lib/experiment/work_server.rb', line 23 def ready? # TODO: get rid of this true end |