Browse Source

Add splay option to offset polling intervals

When the os-collect-config process is started on multiple systems at the
same time, the polling intervals can line up to cause performance
problems against the configuration source. To reduce the impact, this
change adds a splay option to allow the operator to configure a random
delay prior to the polling to attempt to offset the polling
syncronization.

Change-Id: I1a8be3345d783da9014eca7ea26da19d57e767c0
Closes-Bug: #1677314
Alex Schultz 2 years ago
parent
commit
0762fcb0b5
2 changed files with 27 additions and 1 deletions
  1. 17
    1
      os_collect_config/collect.py
  2. 10
    0
      os_collect_config/tests/test_collect.py

+ 17
- 1
os_collect_config/collect.py View File

@@ -16,6 +16,7 @@
16 16
 import hashlib
17 17
 import json
18 18
 import os
19
+import random
19 20
 import shutil
20 21
 import signal
21 22
 import subprocess
@@ -89,7 +90,17 @@ opts = [
89 90
                     help='Key(s) to explode into multiple collected outputs. '
90 91
                     'Parsed according to the expected Metadata created by '
91 92
                     'OS::Heat::StructuredDeployment. Only exploded if seen at '
92
-                    'the root of the Metadata.')
93
+                    'the root of the Metadata.'),
94
+    cfg.FloatOpt('splay',
95
+                 default=0,
96
+                 help='Use this option to sleep for a random amount of time '
97
+                      'prior to starting the collect process. Takes a maximum '
98
+                      'number of seconds to wait before beginning collection '
99
+                      'as an argument. Disabled when set to 0. This option '
100
+                      'can help ensure that multiple collect processes '
101
+                      '(on different hosts) do not attempt to poll at the '
102
+                      'exact same time if they were all started at the same '
103
+                      'time. Ignored if --one-time or --force is used.'),
93 104
 ]
94 105
 
95 106
 CONF = cfg.CONF
@@ -253,6 +264,11 @@ def __main__(args=sys.argv, collector_kwargs_map=None):
253 264
     if CONF.force:
254 265
         CONF.set_override('one_time', True)
255 266
 
267
+    if CONF.splay > 0 and not CONF.one_time:
268
+        # sleep splay seconds in the beginning to prevent multiple collect
269
+        # processes from all running at the same time
270
+        time.sleep(random.randrange(0, CONF.splay))
271
+
256 272
     exitval = 0
257 273
     config_files = CONF.config_file
258 274
     config_hash = getfilehash(config_files)

+ 10
- 0
os_collect_config/tests/test_collect.py View File

@@ -344,6 +344,16 @@ class TestCollect(testtools.TestCase):
344 344
                           ['os-collect-config', 'heat_local', '-i', '10',
345 345
                            '--min-polling-interval', '20', '-c', 'true'])
346 346
 
347
+    @mock.patch('time.sleep')
348
+    @mock.patch('random.randrange')
349
+    def test_main_with_splay(self, randrange_mock, sleep_mock):
350
+        randrange_mock.return_value = 4
351
+        collect.__main__(args=['os-collect-config', 'heat_local', '-i', '10',
352
+                               '--min-polling-interval', '20', '-c', 'true',
353
+                               '--print', '--splay', '29'])
354
+        randrange_mock.assert_called_with(0, 29)
355
+        sleep_mock.assert_called_with(4)
356
+
347 357
 
348 358
 class TestCollectAll(testtools.TestCase):
349 359
 

Loading…
Cancel
Save