From d2a7232d772f84dafadd469c3b91092b201bbfef Mon Sep 17 00:00:00 2001 From: Yolanda Robla Date: Mon, 10 Nov 2014 11:00:46 +0100 Subject: [PATCH] Caching floating ips as server list is done There are individual requets for each node to be built and deleted to query for floating ips list. That means one call to the nova API for each process, causing high load into the system. Adding a cache layer that only queries for the list every 5 seconds, as well as we are doing for the server list. Change-Id: I43dd4805debbdf790c3ec28db686459138d59d4d --- nodepool/provider_manager.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/nodepool/provider_manager.py b/nodepool/provider_manager.py index 350e0a574..a69807867 100644 --- a/nodepool/provider_manager.py +++ b/nodepool/provider_manager.py @@ -33,6 +33,7 @@ from task_manager import Task, TaskManager, ManagerStoppedException SERVER_LIST_AGE = 5 # How long to keep a cached copy of the server list +IPS_LIST_AGE = 5 # How long to keep a cached copy of the ip list ITERATE_INTERVAL = 2 # How long to sleep while waiting for something # in a loop @@ -314,6 +315,9 @@ class ProviderManager(TaskManager): self._servers = [] self._servers_time = 0 self._servers_lock = threading.Lock() + self._ips = [] + self._ips_time = 0 + self._ips_lock = threading.Lock() @property def _flavors(self): @@ -541,7 +545,14 @@ class ProviderManager(TaskManager): return self.submitTask(ListFlavorsTask()) def listFloatingIPs(self): - return self.submitTask(ListFloatingIPsTask()) + if time.time() - self._ips_time >= IPS_LIST_AGE: + if self._ips_lock.acquire(False): + try: + self._ips = self.submitTask(ListFloatingIPsTask()) + self._ips_time = time.time() + finally: + self._ips_lock.release() + return self._ips def removeFloatingIP(self, server_id, address): return self.submitTask(RemoveFloatingIPTask(server=server_id,