From 9efa08d4a322e6331b7b48b3a04b1c0636ed68d3 Mon Sep 17 00:00:00 2001 From: Lianhao Lu Date: Fri, 27 Mar 2015 15:07:02 +0800 Subject: [PATCH] Optimize the flow of getting pollster resources No need to call pollster's default discovery to get the resources if the pipeline has already provided them. Change-Id: Ib8959498b9dfd848087484d3348578733b790c29 Closes-Bug: #1437175 --- ceilometer/agent/base.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ceilometer/agent/base.py b/ceilometer/agent/base.py index e00d70fdb..631c82f16 100644 --- a/ceilometer/agent/base.py +++ b/ceilometer/agent/base.py @@ -130,15 +130,12 @@ class PollingTask(object): LOG.info(_("Polling pollster %(poll)s in the context of " "%(src)s"), dict(poll=pollster.name, src=source_name)) - pollster_resources = [] - if pollster.obj.default_discovery: - pollster_resources = self.manager.discover( - [pollster.obj.default_discovery], discovery_cache) key = Resources.key(source_name, pollster) - source_resources = list( + candidate_res = list( self.resources[key].get(discovery_cache)) - candidate_res = (source_resources or - pollster_resources) + if not candidate_res and pollster.obj.default_discovery: + candidate_res = self.manager.discover( + [pollster.obj.default_discovery], discovery_cache) # Remove duplicated resources and black resources. Using # set() requires well defined __hash__ for each resource.