Make the updates of stats asynchronous
@@ -1145,9 +1145,10 @@ class Djinn
def update_node_info_cache
threads = []
new_stats = []
- @state_change_lock.synchronize {
- @nodes.each { |node|
- ip = node.private_ip
+ ips = []
+
+ @state_change_lock.synchronize { @nodes.each { |node| ips << ip } }
+ ips.each { |ip|
if ip == my_node.private_ip
begin
new_stats << JSON.load(get_node_stats_json(@@secret))
@@ -1171,7 +1172,6 @@ class Djinn
t.join
new_stats << t[:new_stat] unless t[:new_stat].nil?
}
- }
@state_change_lock.synchronize { @cluster_stats = new_stats }
Djinn.log_debug("Updated cluster stats.")
@@ -1812,6 +1812,12 @@ class Djinn
# statistics to the log.
last_print = Time.now.to_i
+ # We use a thread to check the status of the cluster to ensure we
+ # don't block waiting for the status.
+ if my_node.is_shadow?
+ update_stats_thread = Thread.new { update_node_info_cache }
+ end
+
until @kill_sig_received do
# Mark the beginning of the duty cycle.
start_work_time = Time.now.to_i
@@ -1846,7 +1852,11 @@ class Djinn
my_versions_loaded = @versions_loaded if my_node.is_load_balancer?
if my_node.is_shadow?
write_tools_config
- update_node_info_cache
+ if update_stats_thread.alive?
+ Djinn.log_debug("Update thread still running: skipping updates.")
+ else
+ update_stats_thread = Thread.new { update_node_info_cache }
+ end
backup_appcontroller_state
elsif !restore_appcontroller_state
@state = "Couldn't reach the deployment state: now in isolated mode"
@@ -5283,6 +5293,7 @@ HOSTS
# Let's consider the last system load readings we have, to see if the
# node can run another AppServer.
+ @state_change_lock.synchronize {
get_all_compute_nodes.each { |host|
@cluster_stats.each { |node|
next if node['private_ip'] != host
@@ -5322,6 +5333,7 @@ HOSTS
break
}
}
+ }
Djinn.log_debug(
"Hosts available to scale #{version_key}: #{available_hosts}.")
