]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
heat engine : Make wait-condition poll interval better
authorSteven Hardy <shardy@redhat.com>
Wed, 17 Oct 2012 12:37:57 +0000 (13:37 +0100)
committerSteven Hardy <shardy@redhat.com>
Thu, 18 Oct 2012 16:19:29 +0000 (17:19 +0100)
Remove rising-rate sleep-time logic and replace with a bounded
poll interval derived from the timeout - this should avoid ramping
up to a really long interval and delaying stack complete status

Fixes #264

Change-Id: Id53b87a988299708c29fc853f2801f527fd825dd
Signed-off-by: Steven Hardy <shardy@redhat.com>
heat/engine/wait_condition.py

index 179a467f84201f2b78e6f76474ed95c5f9238e0f..fe55fa71cd797dbfe134d98b7084ef00e0024dac 100644 (file)
@@ -65,12 +65,22 @@ class WaitCondition(resources.Resource):
                          'Count': {'Type': 'Number',
                                    'MinValue': '1'}}
 
+    # Sleep time between polling for wait completion
+    # is calculated as a fraction of timeout time
+    # bounded by MIN_SLEEP and MAX_SLEEP
+    MIN_SLEEP = 1  # seconds
+    MAX_SLEEP = 10
+    SLEEP_DIV = 100  # 1/100'th of timeout
+
     def __init__(self, name, json_snippet, stack):
         super(WaitCondition, self).__init__(name, json_snippet, stack)
         self.resource_id = None
 
         self.timeout = int(self.t['Properties']['Timeout'])
         self.count = int(self.t['Properties'].get('Count', '1'))
+        self.sleep_time = max(min(self.MAX_SLEEP,
+                              self.timeout / self.SLEEP_DIV),
+                              self.MIN_SLEEP)
 
     def _get_handle_resource_id(self):
         if self.resource_id is None:
@@ -95,14 +105,14 @@ class WaitCondition(resources.Resource):
                 handle = self.stack[self._get_handle_resource_id()]
 
                 (status, reason) = (WAITING, '')
-                sleep_time = 1
 
                 while status == WAITING:
                     (status, reason) = self._get_status_reason(handle)
                     if status == WAITING:
-                        logger.debug('Waiting for the Metadata[Status]')
-                        eventlet.sleep(sleep_time)
-                        sleep_time = min(sleep_time * 2, self.timeout / 4)
+                        logger.debug('Polling for WaitCondition completion,' +
+                                     ' sleeping for %s seconds, timeout %s' %
+                                     (self.sleep_time, self.timeout))
+                        eventlet.sleep(self.sleep_time)
 
         except eventlet.Timeout as t:
             if t is not tmo: