Commit 5580ef80 authored by Daniele Venzano's avatar Daniele Venzano

Fix #66 by using a barrier to block the scheduler until resources are refreshed

parent 6dcdd480
......@@ -93,6 +93,7 @@ class DockerEngineBackend(zoe_master.backends.base.BaseBackend):
node_stats = _checker.host_stats[host_conf.name]
platform_stats.nodes.append(node_stats)
platform_stats.timestamp = time.time()
return platform_stats
def _update_node_state(self, host_conf: DockerHostConfig, node_stats: NodeStats, get_usage_stats: bool):
......
......@@ -26,8 +26,6 @@ from zoe_master.metrics.kairosdb import KairosDBInMetrics
log = logging.getLogger(__name__)
METRIC_INTERVAL = 20
def time_diff_ms(start: float, end: float) -> int:
"""Return a time difference in milliseconds."""
......@@ -37,12 +35,16 @@ def time_diff_ms(start: float, end: float) -> int:
class StatsManager(threading.Thread):
"""Class for collecting and sending out metrics and statistics."""
METRIC_INTERVAL = 20
def __init__(self, state):
super().__init__(name='metrics', daemon=True)
self.state = state
self.deployment_name = get_conf().deployment_name
self.stop = threading.Event()
self._current_platform_stats = None
self.barrier = threading.Event()
self.barrier.clear()
if get_conf().kairosdb_enable:
self.usage_metrics = KairosDBInMetrics()
else:
......@@ -89,11 +91,14 @@ class StatsManager(threading.Thread):
node.cores_in_use = node_cores
node.memory_in_use = node_memory
sleep_time = METRIC_INTERVAL - (time.time() - time_start)
self.barrier.set()
self.barrier.clear()
sleep_time = self.METRIC_INTERVAL - (time.time() - time_start)
if sleep_time > 0 and self.stop.wait(timeout=sleep_time):
break
@property
def current_stats(self):
"""Returns a snapshot of the current metrics."""
self.barrier.wait()
return deepcopy(self._current_platform_stats)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment