mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Merge pull request #158 from pitchum/perf-debug
* Logging time needed to load the python module for an action (versus time needed to execute it). * Lazy load some python imports (perfs improved a lot).
This commit is contained in:
commit
97f8593ba1
2 changed files with 5 additions and 2 deletions
|
@ -469,10 +469,13 @@ class ActionsMap(object):
|
||||||
|
|
||||||
# Lock the moulinette for the namespace
|
# Lock the moulinette for the namespace
|
||||||
with MoulinetteLock(namespace, timeout):
|
with MoulinetteLock(namespace, timeout):
|
||||||
|
start = time()
|
||||||
try:
|
try:
|
||||||
mod = __import__('%s.%s' % (namespace, category),
|
mod = __import__('%s.%s' % (namespace, category),
|
||||||
globals=globals(), level=0,
|
globals=globals(), level=0,
|
||||||
fromlist=[func_name])
|
fromlist=[func_name])
|
||||||
|
logger.debug('loading python module %s took %.3fs',
|
||||||
|
'%s.%s' % (namespace, category), time() - start)
|
||||||
func = getattr(mod, func_name)
|
func = getattr(mod, func_name)
|
||||||
except (AttributeError, ImportError):
|
except (AttributeError, ImportError):
|
||||||
logger.exception("unable to load function %s.%s",
|
logger.exception("unable to load function %s.%s",
|
||||||
|
@ -495,7 +498,7 @@ class ActionsMap(object):
|
||||||
return func(**arguments)
|
return func(**arguments)
|
||||||
finally:
|
finally:
|
||||||
stop = time()
|
stop = time()
|
||||||
logger.debug('action [%s] ended after %.3fs',
|
logger.debug('action [%s] executed in %.3fs',
|
||||||
log_id, stop - start)
|
log_id, stop - start)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import errno
|
import errno
|
||||||
import requests
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from moulinette import m18n
|
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
|
expected_status_code -- Status code expected from the request. Can be
|
||||||
None to ignore the status code.
|
None to ignore the status code.
|
||||||
"""
|
"""
|
||||||
|
import requests # lazy loading this module for performance reasons
|
||||||
# Assumptions
|
# Assumptions
|
||||||
assert isinstance(url, str)
|
assert isinstance(url, str)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue