From 0cd9cb41248ef24ae04c9e35f50cb8f3f847cac4 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Fri, 30 Mar 2018 18:37:27 +0000 Subject: [PATCH] Pre-load the list of image drivers In before, we load the image drivers on demand. This is undesirable because the image driver will be loaded per request which is unnecessary. After this patch, the image drivers will be loaded on initialization. Each request will retrieve the pre-loaded driver instead. Change-Id: If67610f27dc2fd1d95196b8cdb1e99bcb0f03080 --- zun/container/docker/driver.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/zun/container/docker/driver.py b/zun/container/docker/driver.py index dcc21b37a..45a416fa0 100644 --- a/zun/container/docker/driver.py +++ b/zun/container/docker/driver.py @@ -102,6 +102,10 @@ class DockerDriver(driver.ContainerDriver): self._host = host.Host() self._get_host_storage_info() self.volume_driver = vol_driver.driver() + self.image_drivers = {} + for driver_name in CONF.image_driver_list: + driver = img_driver.load_image_driver(driver_name) + self.image_drivers[driver_name] = driver def _get_host_storage_info(self): storage_info = self._host.get_storage_info() @@ -140,7 +144,7 @@ class DockerDriver(driver.ContainerDriver): driver_name = CONF.default_image_driver try: - image_driver = img_driver.load_image_driver(driver_name) + image_driver = self.image_drivers[driver_name] image, image_loaded = image_driver.pull_image( context, repo, tag, image_pull_policy) if image: @@ -157,8 +161,11 @@ class DockerDriver(driver.ContainerDriver): return image, image_loaded def search_image(self, context, repo, tag, driver_name, exact_match): + if driver_name is None: + driver_name = CONF.default_image_driver + try: - image_driver = img_driver.load_image_driver(driver_name) + image_driver = self.image_drivers[driver_name] return image_driver.search_image(context, repo, tag, exact_match) except Exception as e: