From 5f563d39532c6f86ca4a312a5a29699ff64e0a08 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 1 Sep 2010 14:56:02 +0200 Subject: [PATCH] Optimized getting new actions in VirtualMachineDriver --- src/mad/ruby/ActionManager.rb | 7 ++++-- src/mad/ruby/VirtualMachineDriver.rb | 37 +++++++++++++++++++++------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/mad/ruby/ActionManager.rb b/src/mad/ruby/ActionManager.rb index 861ea5a558..5b26809802 100644 --- a/src/mad/ruby/ActionManager.rb +++ b/src/mad/ruby/ActionManager.rb @@ -164,8 +164,7 @@ class ActionManager def start_listener while true @threads_mutex.synchronize { - while ((@concurrency - @num_running)==0) || - @action_queue.size==0 + while ((@concurrency - @num_running)==0) || empty_queue @threads_cond.wait(@threads_mutex) return if (@finalize && @num_running == 0) @@ -185,6 +184,10 @@ private def get_runable_action @action_queue.shift end + + def empty_queue + @action_queue.size==0 + end def run_action action = get_runable_action diff --git a/src/mad/ruby/VirtualMachineDriver.rb b/src/mad/ruby/VirtualMachineDriver.rb index 38244a4031..c5694f20db 100644 --- a/src/mad/ruby/VirtualMachineDriver.rb +++ b/src/mad/ruby/VirtualMachineDriver.rb @@ -60,7 +60,7 @@ class VirtualMachineDriver < OpenNebulaDriver :unknown => '-' } - HOST_ARG = 2 + HOST_ARG = 1 # ------------------------------------------------------------------------- # Register default actions for the protocol @@ -167,22 +167,41 @@ private end end + def get_first_runable + action_index=@action_queue.index do |action| + if action[:args][HOST_ARG] + !@hosts.include? action[:args][HOST_ARG] + else + true + end + end + + if action_index + @action_queue[action_index] + else + nil + end + end + def get_runable_action - action=@action_queue.select do |a| - if a[:args][HOST_ARG] - @hosts.include? a[:args][HOST_ARG] - else - true - end - end.first + action=get_first_runable if action @hosts << action[:args][HOST_ARG] if action[:args][HOST_ARG] @action_queue.delete(action) end - + + STDERR.puts "action: #{action.inspect}" + STDERR.puts "queue: #{@action_queue.inspect}" + STDERR.puts "hosts: #{@hosts.inspect}" + STDERR.flush + return action end + + def empty_queue + get_first_runable==nil + end end if __FILE__ == $0