Commit c1a0048b authored by Daniele Venzano's avatar Daniele Venzano

Tune debug messages and clean up

parent 933af967
...@@ -29,7 +29,7 @@ class SimulatedNode: ...@@ -29,7 +29,7 @@ class SimulatedNode:
self.name = real_node.name self.name = real_node.name
self.labels = real_node.labels self.labels = real_node.labels
self.images = list_available_images(self.name) self.images = list_available_images(self.name)
log.debug('Node {}: m {} | c {} | l {}'.format(self.name, self.node_free_memory() / (1024 ** 2), self.node_free_cores(), list(self.labels))) log.debug('Node {}: m {:.2f}GB | c {} | l {} | ncont {}'.format(self.name, self.node_free_memory() / (1024 ** 3), self.node_free_cores(), list(self.labels), self.container_count))
def service_fits(self, service: Service) -> bool: def service_fits(self, service: Service) -> bool:
"""Checks whether a service can fit in this node""" """Checks whether a service can fit in this node"""
...@@ -114,49 +114,37 @@ class SimulatedPlatform: ...@@ -114,49 +114,37 @@ class SimulatedPlatform:
self.nodes[node.name] = SimulatedNode(node) self.nodes[node.name] = SimulatedNode(node)
def _select_node_policy(self, node_list: List[SimulatedNode]) -> SimulatedNode: def _select_node_policy(self, node_list: List[SimulatedNode]) -> SimulatedNode:
log.debug('Node selection with {} policy'.format(get_conf().placement_policy))
selected = None
if get_conf().placement_policy == "random": if get_conf().placement_policy == "random":
selected = random.choice(node_list) selected = random.choice(node_list)
elif get_conf().placement_policy == "waterfill": elif get_conf().placement_policy == "waterfill":
node_list.sort(key=lambda n: (len(n.labels), -n.container_count)) # biggest container_count first, lowest label count first node_list.sort(key=lambda n: (len(n.labels), -n.container_count)) # biggest container_count first, lowest label count first
for node in node_list: selected = node_list[0]
if len(node.labels) == 0:
selected = node
break
if selected is None:
selected = node_list[0]
elif get_conf().placement_policy == "average": elif get_conf().placement_policy == "average":
node_list.sort(key=lambda n: (len(n.labels), n.container_count)) # smallest container_count first, lowest label count first node_list.sort(key=lambda n: (len(n.labels), n.container_count)) # smallest container_count first, lowest label count first
for node in node_list: selected = node_list[0]
if len(node.labels) == 0:
selected = node
break
if selected is None:
selected = node_list[0]
else: else:
log.error('Unknown placement policy: {}'.format(get_conf().placement_policy)) log.error('Unknown placement policy: {}'.format(get_conf().placement_policy))
selected = node_list[0] selected = node_list[0]
for node in node_list: for node in node_list:
log.debug(' -> {}: {} {}'.format(node.name, node.container_count, len(node.labels))) log.debug(' -> {}: {} {}'.format(node.name, len(node.labels), node.container_count))
log.debug('Selected node {}'.format(selected.name))
return selected return selected
def allocate_essential(self, execution: Execution) -> bool: def allocate_essential(self, execution: Execution) -> bool:
"""Try to find an allocation for essential services""" """Try to find an allocation for essential services"""
for service in execution.essential_services: for service in execution.essential_services:
candidate_nodes = [] candidate_nodes = []
reasons = ''
for node_id_, node in self.nodes.items(): for node_id_, node in self.nodes.items():
if node.service_fits(service): if node.service_fits(service):
candidate_nodes.append(node) candidate_nodes.append(node)
else: else:
log.debug('Cannot fit essential service {} on node {}: {}'.format(service.id, node.name, node.service_why_unfit(service))) reasons += 'node {}: {} ## '.format(service.id, node.name, node.service_why_unfit(service))
if len(candidate_nodes) == 0: # this service does not fit anywhere if len(candidate_nodes) == 0: # this service does not fit anywhere
self.deallocate_essential(execution) self.deallocate_essential(execution)
log.info('Cannot fit essential service {} anywhere, bailing out'.format(service.id)) log.info('Cannot fit essential service {} anywhere, reasons: {}'.format(service.id, reasons))
return False return False
log.debug('Node selection for service {} with {} policy'.format(service.id, get_conf().placement_policy))
selected_node = self._select_node_policy(candidate_nodes) selected_node = self._select_node_policy(candidate_nodes)
selected_node.service_add(service) selected_node.service_add(service)
return True return True
...@@ -175,14 +163,16 @@ class SimulatedPlatform: ...@@ -175,14 +163,16 @@ class SimulatedPlatform:
if service.status == service.ACTIVE_STATUS and service.backend_status != service.BACKEND_DIE_STATUS: if service.status == service.ACTIVE_STATUS and service.backend_status != service.BACKEND_DIE_STATUS:
continue continue
candidate_nodes = [] candidate_nodes = []
reasons = ''
for node_id_, node in self.nodes.items(): for node_id_, node in self.nodes.items():
if node.service_fits(service): if node.service_fits(service):
candidate_nodes.append(node) candidate_nodes.append(node)
else: else:
log.debug('Cannot fit elastic service {} on node {}: {}'.format(service.id, node.name, node.service_why_unfit(service))) reasons += 'node {}: {} ## '.format(service.id, node.name, node.service_why_unfit(service))
if len(candidate_nodes) == 0: # this service does not fit anywhere if len(candidate_nodes) == 0: # this service does not fit anywhere
log.info('Cannot fit elastic service {} anywhere'.format(service.id)) log.info('Cannot fit elastic service {} anywhere, reasons: {}'.format(service.id, reasons))
continue continue
log.debug('Node selection for service {} with {} policy'.format(service.id, get_conf().placement_policy))
selected_node = self._select_node_policy(candidate_nodes) selected_node = self._select_node_policy(candidate_nodes)
selected_node.service_add(service) selected_node.service_add(service)
service.set_runnable() service.set_runnable()
......
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