making use of threadpools to boot each node and boot the services within a node

This commit is contained in:
Blake J. Harnden 2018-06-20 16:18:30 -07:00
parent ed4e6f0f00
commit 08956e7b93
3 changed files with 18 additions and 5 deletions

View file

@ -221,7 +221,7 @@ class CoreServices(object):
self.defaultservices.clear() self.defaultservices.clear()
self.customservices.clear() self.customservices.clear()
def node_service_startups(self, services): def node_service_dependencies(self, services):
# generate service map and find starting points # generate service map and find starting points
node_services = {service.name: service for service in services} node_services = {service.name: service for service in services}
is_dependency = set() is_dependency = set()
@ -424,6 +424,7 @@ class CoreServices(object):
continue continue
except ValueError: except ValueError:
logger.exception("error converting start time to float") logger.exception("error converting start time to float")
# self.bootnodeservice(node, service, services)
result = pool.apply_async(self.bootnodeservice, (node, service, services)) result = pool.apply_async(self.bootnodeservice, (node, service, services))
results.append(result) results.append(result)

View file

@ -10,6 +10,7 @@ import subprocess
import tempfile import tempfile
import threading import threading
import time import time
from multiprocessing.pool import ThreadPool
import pwd import pwd
@ -716,13 +717,24 @@ class Session(object):
request flag. request flag.
""" """
with self._objects_lock: with self._objects_lock:
pool = ThreadPool()
results = []
start = time.time()
for obj in self.objects.itervalues(): for obj in self.objects.itervalues():
# TODO: PyCoreNode is not the type to check # TODO: PyCoreNode is not the type to check
if isinstance(obj, nodes.PyCoreNode) and not nodeutils.is_node(obj, NodeTypes.RJ45): if isinstance(obj, nodes.PyCoreNode) and not nodeutils.is_node(obj, NodeTypes.RJ45):
# add a control interface if configured # add a control interface if configured
logger.info("booting node: %s", obj.name) logger.info("booting node: %s", obj.name)
self.add_remove_control_interface(node=obj, remove=False) self.add_remove_control_interface(node=obj, remove=False)
obj.boot() result = pool.apply_async(obj.boot)
results.append(result)
pool.close()
pool.join()
for result in results:
result.get()
logger.info("BOOT RUN TIME: %s", time.time() - start)
self.update_control_interface_hosts() self.update_control_interface_hosts()

View file

@ -59,7 +59,7 @@ class TestServices:
] ]
# when # when
startups = session.services.get_service_startups(services) startups = session.services.node_service_dependencies(services)
# then # then
assert len(startups) == 2 assert len(startups) == 2
@ -75,7 +75,7 @@ class TestServices:
# when # when
with pytest.raises(ValueError): with pytest.raises(ValueError):
session.services.get_service_startups(services) session.services.node_service_dependencies(services)
def test_services_dependencies_cycle(self, session): def test_services_dependencies_cycle(self, session):
# given # given
@ -91,4 +91,4 @@ class TestServices:
# when # when
with pytest.raises(ValueError): with pytest.raises(ValueError):
session.services.get_service_startups(services) session.services.node_service_dependencies(services)