mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-22 17:57:46 +03:00
Optimized getting new actions in VirtualMachineDriver
This commit is contained in:
parent
175b312915
commit
5f563d3953
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user