]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/standalone/ceph-helpers.sh: Thinner resolution in get_timeout_delays()
authorErwan Velu <erwan@redhat.com>
Thu, 7 Jun 2018 13:56:45 +0000 (15:56 +0200)
committerErwan Velu <erwan@redhat.com>
Mon, 25 Jun 2018 20:09:14 +0000 (22:09 +0200)
get_timeout_delays() is a generic function to compute delays for a long
period of time without saturating the CPU is busy loops.

It works pretty fine when the delay is short like having the following
series when requesting a 20seconds timeout : "0.1 0.2 0.4 0.8 1.6 3.2 6.4 7.3 ".
Here the maximum between two loops is 7.3 which is perfectly fine.

When the timeout reaches 300sec, the same code produces the following
series : "0.1 0.2 0.4 0.8 1.6 3.2 6.4 12.8 25.6 51.2 102.4 95.3 "
In such example there is delays which are nearly 2 minutes !

That is not efficient as the expected event, between two loops, could
arrive just after this long sleep occurs making a minute+ sleep for
nothing. On a local system that could be ok while on a CI, if all jobs
run like CI the overall is pretty unefficient by generating useless CPU
waits.

This patch is about adding a maximum acceptable delay time between two
loops while keeping the same rampup behavior.

On the same 300 seconds delay example, with MAX_TIMEOUT set to 10, we
now have the following series: "0.1 0.2 0.4 0.8 1.6 3.2 6.4 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 7.3"
We can see that the long 12/25/51/102/95 values vanished and being
replaced by a series of 10 seconds. It's up to every test defining the
probability of having a soonish event to complete.

The MAX_TIMEOUT is set to 15seconds.
Signed-off-by: Erwan Velu <erwan@redhat.com>
qa/standalone/ceph-helpers.sh

index 2cae98bc5ff42db6e5fb7f5d618d10fc7acbd443..ef505873757b7dc8fcbbfa7b48fbc556adf4149b 100755 (executable)
@@ -19,6 +19,7 @@
 #
 TIMEOUT=300
 WAIT_FOR_CLEAN_TIMEOUT=90
+MAX_TIMEOUT=15
 PG_NUM=4
 CEPH_BUILD_VIRTUALENV=${TMPDIR:-/tmp}
 
@@ -1408,6 +1409,7 @@ function get_timeout_delays() {
     $trace && shopt -u -o xtrace
     local timeout=$1
     local first_step=${2:-1}
+    local max_timeout=${3:-$MAX_TIMEOUT}
 
     local i
     local total="0"
@@ -1416,6 +1418,13 @@ function get_timeout_delays() {
         echo -n "$(calc $i) "
         total=$(calc $total + $i)
         i=$(calc $i \* 2)
+        if [ $max_timeout -gt 0 ]; then
+            # Did we reach max timeout ?
+            if [ ${i%.*} -eq ${max_timeout%.*} ] && [ ${i#*.} \> ${max_timeout#*.} ] || [ ${i%.*} -gt ${max_timeout%.*} ]; then
+                # Yes, so let's cap the max wait time to max
+                i=$max_timeout
+            fi
+        fi
     done
     if test "$(calc $total \< $timeout)" = "1"; then
         echo -n "$(calc $timeout - $total) "
@@ -1435,6 +1444,8 @@ function test_get_timeout_delays() {
     test "$(get_timeout_delays 6 .1)" = "0.1 0.2 0.4 0.8 1.6 2.9 " || return 1
     test "$(get_timeout_delays 6.3 .1)" = "0.1 0.2 0.4 0.8 1.6 3.2 " || return 1
     test "$(get_timeout_delays 20 .1)" = "0.1 0.2 0.4 0.8 1.6 3.2 6.4 7.3 " || return 1
+    test "$(get_timeout_delays 300 .1)" = "0.1 0.2 0.4 0.8 1.6 3.2 6.4 12.8 25.6 51.2 102.4 95.3 " || return 1
+    test "$(get_timeout_delays 300 .1 10)" = "0.1 0.2 0.4 0.8 1.6 3.2 6.4 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 7.3" || return 1
 }
 
 #######################################################################