summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@oath.com>2018-07-17 18:08:05 +0200
committerHenning Baldersheim <balder@oath.com>2018-07-17 18:08:05 +0200
commitfc8907289a23c1f5dc10da18f7e48d6b572aaa88 (patch)
tree3a97162a5b363c78423a373dfc75b2cd0fded286 /searchcore
parent8bff92aa93ec5caa7c5d2a9173ef1792cfd428f0 (diff)
Prevent changes above 10%
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/tests/proton/matching/matching_stats_test.cpp4
-rw-r--r--searchcore/src/vespa/searchcore/proton/matching/matching_stats.cpp8
2 files changed, 12 insertions, 0 deletions
diff --git a/searchcore/src/tests/proton/matching/matching_stats_test.cpp b/searchcore/src/tests/proton/matching/matching_stats_test.cpp
index 26eaa127aa3..78a53fb668d 100644
--- a/searchcore/src/tests/proton/matching/matching_stats_test.cpp
+++ b/searchcore/src/tests/proton/matching/matching_stats_test.cpp
@@ -271,6 +271,10 @@ TEST("requireThatSoftDoomFacorIsComputedCorrectly") {
stats.updatesoftDoomFactor(1.0, 0.0009, 2.0); // soft limits less than 1ms should be ignored
EXPECT_EQUAL(1ul, stats.softDoomed());
EXPECT_EQUAL(0.44, stats.softDoomFactor());
+ stats.updatesoftDoomFactor(1.0, 0.5, 10.0); // Prevent changes above 10%
+ EXPECT_EQUAL(1ul, stats.softDoomed());
+ EXPECT_EQUAL(0.396, stats.softDoomFactor());
+
}
TEST_MAIN() {
diff --git a/searchcore/src/vespa/searchcore/proton/matching/matching_stats.cpp b/searchcore/src/vespa/searchcore/proton/matching/matching_stats.cpp
index 2b4660adc11..90d0c05c349 100644
--- a/searchcore/src/vespa/searchcore/proton/matching/matching_stats.cpp
+++ b/searchcore/src/vespa/searchcore/proton/matching/matching_stats.cpp
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "matching_stats.h"
+#include <cmath>
namespace proton::matching {
@@ -14,6 +15,7 @@ MatchingStats::Partition &get_writable_partition(std::vector<MatchingStats::Part
}
constexpr double MIN_TIMEOUT = 0.001;
+constexpr double MAX_CHANGE_FACTOR = 5;
} // namespace proton::matching::<unnamed>
@@ -78,11 +80,17 @@ MatchingStats::add(const MatchingStats &rhs)
MatchingStats &
MatchingStats::updatesoftDoomFactor(double hardLimit, double softLimit, double duration) {
+ // The safety capping here should normally not be necessary all input numbers
+ // will normally be within reasonable values.
+ // It is merely a safety measure to avoid overflow on bad input as can happend with time senstive stuff
+ // in any soft real time system.
if ((hardLimit >= MIN_TIMEOUT) && (softLimit >= MIN_TIMEOUT)) {
double diff = (softLimit - duration)/hardLimit;
if (duration < softLimit) {
+ diff = std::min(diff, _softDoomFactor*MAX_CHANGE_FACTOR);
_softDoomFactor += 0.01*diff;
} else {
+ diff = std::max(diff, -_softDoomFactor*MAX_CHANGE_FACTOR);
_softDoomFactor += 0.02*diff;
}
}