From 4e379dcf9f43f7d431e2ab1c6967244a5fe96f74 Mon Sep 17 00:00:00 2001 From: pitchum Date: Sun, 22 Apr 2018 00:27:53 +0200 Subject: [PATCH 1/2] Logging time needed to load the python module for an action (versus time needed to execute it). --- moulinette/actionsmap.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index 9e1468f1..5951ca59 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -469,10 +469,13 @@ class ActionsMap(object): # Lock the moulinette for the namespace with MoulinetteLock(namespace, timeout): + start = time() try: mod = __import__('%s.%s' % (namespace, category), globals=globals(), level=0, fromlist=[func_name]) + logger.debug('loading python module %s took %.3fs', + '%s.%s' % (namespace, category), time() - start) func = getattr(mod, func_name) except (AttributeError, ImportError): logger.exception("unable to load function %s.%s", @@ -495,7 +498,7 @@ class ActionsMap(object): return func(**arguments) finally: stop = time() - logger.debug('action [%s] ended after %.3fs', + logger.debug('action [%s] executed in %.3fs', log_id, stop - start) @staticmethod From cd4581c3df075c9f66dc4d3a758648613bdd55eb Mon Sep 17 00:00:00 2001 From: pitchum Date: Sun, 22 Apr 2018 00:31:14 +0200 Subject: [PATCH 2/2] Lazy load some python imports (perfs improved a lot). --- moulinette/utils/network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moulinette/utils/network.py b/moulinette/utils/network.py index c083dea6..27e753e3 100644 --- a/moulinette/utils/network.py +++ b/moulinette/utils/network.py @@ -1,5 +1,4 @@ import errno -import requests import json from moulinette import m18n @@ -17,6 +16,7 @@ def download_text(url, timeout=30, expected_status_code=200): expected_status_code -- Status code expected from the request. Can be None to ignore the status code. """ + import requests # lazy loading this module for performance reasons # Assumptions assert isinstance(url, str)