[ARVADOS] created: 2a0472e6b0e94265d78fb22b5652619a7700e86b

Git user git at public.curoverse.com
Thu Nov 3 13:46:45 EDT 2016


        at  2a0472e6b0e94265d78fb22b5652619a7700e86b (commit)


commit 2a0472e6b0e94265d78fb22b5652619a7700e86b
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Thu Oct 27 21:54:14 2016 -0400

    9849: Cache docker lookup.

diff --git a/sdk/cwl/arvados_cwl/arvdocker.py b/sdk/cwl/arvados_cwl/arvdocker.py
index 244dd3d..f9dba6e 100644
--- a/sdk/cwl/arvados_cwl/arvdocker.py
+++ b/sdk/cwl/arvados_cwl/arvdocker.py
@@ -1,19 +1,28 @@
 import logging
 import sys
+import threading
 
 import cwltool.docker
 from cwltool.errors import WorkflowException
 import arvados.commands.keepdocker
 
-
 logger = logging.getLogger('arvados.cwl-runner')
 
+cached_lookups = {}
+cached_lookups_lock = threading.Lock()
+
 def arv_docker_get_image(api_client, dockerRequirement, pull_image, project_uuid):
     """Check if a Docker image is available in Keep, if not, upload it using arv-keepdocker."""
 
     if "dockerImageId" not in dockerRequirement and "dockerPull" in dockerRequirement:
         dockerRequirement["dockerImageId"] = dockerRequirement["dockerPull"]
 
+    global cached_lookups
+    global cached_lookups_lock
+    with cached_lookups_lock:
+        if dockerRequirement["dockerImageId"] in cached_lookups:
+            return cached_lookups[dockerRequirement["dockerImageId"]]
+
     sp = dockerRequirement["dockerImageId"].split(":")
     image_name = sp[0]
     image_tag = sp[1] if len(sp) > 1 else None
@@ -44,4 +53,14 @@ def arv_docker_get_image(api_client, dockerRequirement, pull_image, project_uuid
         raise WorkflowException("Could not find Docker image %s:%s" % (image_name, image_tag))
 
     pdh = api_client.collections().get(uuid=images[0][0]).execute()["portable_data_hash"]
+
+    with cached_lookups_lock:
+        cached_lookups[dockerRequirement["dockerImageId"]] = pdh
+
     return pdh
+
+def arv_docker_clear_cache():
+    global cached_lookups
+    global cached_lookups_lock
+    with cached_lookups_lock:
+        cached_lookups = {}
diff --git a/sdk/cwl/tests/test_container.py b/sdk/cwl/tests/test_container.py
index 8ca5398..93100ae 100644
--- a/sdk/cwl/tests/test_container.py
+++ b/sdk/cwl/tests/test_container.py
@@ -1,4 +1,5 @@
 import arvados_cwl
+from arvados_cwl.arvdocker import arv_docker_clear_cache
 import logging
 import mock
 import unittest
@@ -21,6 +22,8 @@ class TestContainer(unittest.TestCase):
     @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
     def test_run(self, keepdocker):
         for enable_reuse in (True, False):
+            arv_docker_clear_cache()
+
             runner = mock.MagicMock()
             runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
             runner.ignore_docker_for_reuse = False
@@ -72,6 +75,7 @@ class TestContainer(unittest.TestCase):
     # For the remaining fields, the defaults will apply: {'cores': 1, 'ram': 1024, 'outdirSize': 1024, 'tmpdirSize': 1024}
     @mock.patch("arvados.commands.keepdocker.list_images_in_arv")
     def test_resource_requirements(self, keepdocker):
+        arv_docker_clear_cache()
         runner = mock.MagicMock()
         runner.project_uuid = "zzzzz-8i9sb-zzzzzzzzzzzzzzz"
         runner.ignore_docker_for_reuse = False

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list