From b5004a4e0e7f319197ade05dace741ba18c8b0c0 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Fri, 16 Sep 2016 00:43:38 +0200 Subject: [PATCH] Don't create useless threads This change doesn't create periodic stuff is we have nothing to do. Change-Id: Ibb1f0eaf79be60bb9263f2feaa84c17213f70bd2 --- ceilometer/agent/manager.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ceilometer/agent/manager.py b/ceilometer/agent/manager.py index eff7e8bf41..5ac0d83ab2 100644 --- a/ceilometer/agent/manager.py +++ b/ceilometer/agent/manager.py @@ -392,6 +392,10 @@ class AgentManager(service_base.PipelineBasedService): data = self.setup_polling_tasks() + # Don't start useless threads if no task will run + if not data: + return + # One thread per polling tasks is enough self.polling_periodics = periodics.PeriodicWorker.create( [], executor_factory=lambda: @@ -408,9 +412,7 @@ class AgentManager(service_base.PipelineBasedService): utils.spawn_thread(utils.delayed, delay_time, self.polling_periodics.add, task, polling_task) - if data: - # Don't start useless threads if no task will run - utils.spawn_thread(self.polling_periodics.start, allow_empty=True) + utils.spawn_thread(self.polling_periodics.start, allow_empty=True) def run(self): super(AgentManager, self).run()