summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Musso <hashar@free.fr>2019-10-28 17:41:44 +0100
committerAntoine Musso <hashar@free.fr>2019-10-28 21:47:14 +0100
commit9c78c092038e2baa56698fd69603db898dd79196 (patch)
tree15bbd341311211507164ad26ec6eefd9c8d6de37
parentda1e227c8c80e4c280d172c4e830b6d27a17d86f (diff)
downloadpython-jenkins-job-builder-9c78c092038e2baa56698fd69603db898dd79196.tar.gz
python-jenkins-job-builder-9c78c092038e2baa56698fd69603db898dd79196.tar.xz
python-jenkins-job-builder-9c78c092038e2baa56698fd69603db898dd79196.zip
registry: preload entrypoints before caching
When profiling a JJB run against Wikimedia configuration files [0], I noticed a lot of calls to package_resource trying to figure out the version. Years ago, I already added coded to cache the entrypoints, unfortunately only the entry point definition got cached not the underlying function. Thus each entry point ends up invoking a load() which dramatically slow down JJB. A low hanging fruit is to invoke load() and cache the returned function. Doing so, the run time goes down from 28 seconds down to 17 seconds. [0] https://gerrit.wikimedia.org/g/integration/config/+/master/jjb/ Change-Id: I336b556f28328d8acbdd71c43c8775d55c3720d8
-rw-r--r--jenkins_jobs/registry.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/jenkins_jobs/registry.py b/jenkins_jobs/registry.py
index 2c997737..38ee4a55 100644
--- a/jenkins_jobs/registry.py
+++ b/jenkins_jobs/registry.py
@@ -184,6 +184,7 @@ class ModuleRegistry(object):
# Look for a component function defined in an entry point
eps = self._entry_points_cache.get(component_list_type)
if eps is None:
+ logging.debug("Caching entrypoints for %s" % component_list_type)
module_eps = []
# auto build entry points by inferring from base component_types
mod = pkg_resources.EntryPoint(
@@ -245,7 +246,7 @@ class ModuleRegistry(object):
"name: '{1}'".format(component_type, name)
)
- eps[module_ep.name] = module_ep
+ eps[module_ep.name] = module_ep.load()
# cache both sets of entry points
self._entry_points_cache[component_list_type] = eps
@@ -268,7 +269,7 @@ class ModuleRegistry(object):
# the arguments are interpolated into the real defn.
self.dispatch(component_type, xml_parent, b, component_data)
elif name in eps:
- func = eps[name].load()
+ func = eps[name]
func(self, xml_parent, component_data)
else:
raise JenkinsJobsException(