|
14 | 14 | #include "base/convert.hpp"
|
15 | 15 | #include "base/utility.hpp"
|
16 | 16 | #include "base/context.hpp"
|
| 17 | +#include <cstdlib> |
17 | 18 |
|
18 | 19 | using namespace icinga;
|
19 | 20 |
|
@@ -67,7 +68,7 @@ void Checkable::UpdateNextCheck(const MessageOrigin::Ptr& origin)
|
67 | 68 | if (adj != 0.0)
|
68 | 69 | adj = std::min(0.5 + fmod(GetSchedulingOffset(), interval * 5) / 100.0, adj);
|
69 | 70 |
|
70 |
| - double nextCheck = now - adj + interval; |
| 71 | + double nextCheck = now - adj + interval * GetIntervalShuffleFactor(); |
71 | 72 | double lastCheck = GetLastCheck();
|
72 | 73 |
|
73 | 74 | Log(LogDebug, "Checkable")
|
@@ -278,7 +279,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
|
278 | 279 | if (!parent->GetEnableActiveChecks())
|
279 | 280 | continue;
|
280 | 281 |
|
281 |
| - if (parent->GetNextCheck() >= now + parent->GetRetryInterval()) { |
| 282 | + if (parent->GetNextCheck() >= now + parent->GetRetryInterval() * parent->GetIntervalShuffleFactor()) { |
282 | 283 | ObjectLock olock(parent);
|
283 | 284 | parent->SetNextCheck(now);
|
284 | 285 | }
|
@@ -382,7 +383,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
|
382 | 383 | if (ttl > 0)
|
383 | 384 | offset = ttl;
|
384 | 385 | else
|
385 |
| - offset = GetCheckInterval(); |
| 386 | + offset = GetCheckInterval() * GetIntervalShuffleFactor(); |
386 | 387 |
|
387 | 388 | SetNextCheck(Utility::GetTime() + offset, false, origin);
|
388 | 389 | }
|
@@ -667,3 +668,20 @@ void Checkable::AquirePendingCheckSlot(int maxPendingChecks)
|
667 | 668 |
|
668 | 669 | m_PendingChecks++;
|
669 | 670 | }
|
| 671 | + |
| 672 | +/** |
| 673 | + * Returns a random factor derived from scheduler_shuffle_cap to multiply the check interval with. |
| 674 | + * |
| 675 | + * E.g. if scheduler_shuffle_cap is 20 (%), this function returns [0.8, 1.2]. |
| 676 | + */ |
| 677 | +double Checkable::GetIntervalShuffleFactor() |
| 678 | +{ |
| 679 | + if (!GetEnableActiveChecks()) { |
| 680 | + // scheduler_shuffle_cap doesn't influence external checkers. |
| 681 | + return 1; |
| 682 | + } |
| 683 | + |
| 684 | + return (GetSchedulerShuffleCap() / 100) // scheduler_shuffle_cap as non-%, i.e. 10 => 0.1 |
| 685 | + * (rand() / (double)RAND_MAX * 2 - 1) // random number [-1, 1] |
| 686 | + + 1; |
| 687 | +} |
0 commit comments