|
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")
|
@@ -384,7 +385,7 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
|
384 | 385 | if (ttl > 0)
|
385 | 386 | offset = ttl;
|
386 | 387 | else
|
387 |
| - offset = GetCheckInterval(); |
| 388 | + offset = GetCheckInterval() * GetIntervalShuffleFactor(); |
388 | 389 |
|
389 | 390 | SetNextCheck(Utility::GetTime() + offset);
|
390 | 391 | }
|
@@ -425,7 +426,7 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
|
425 | 426 | if (!parent->GetEnableActiveChecks())
|
426 | 427 | continue;
|
427 | 428 |
|
428 |
| - if (parent->GetNextCheck() >= now + parent->GetRetryInterval()) { |
| 429 | + if (parent->GetNextCheck() >= now + parent->GetRetryInterval() * parent->GetIntervalShuffleFactor()) { |
429 | 430 | ObjectLock olock(parent);
|
430 | 431 | parent->SetNextCheck(now);
|
431 | 432 | }
|
@@ -720,3 +721,20 @@ void Checkable::AquirePendingCheckSlot(int maxPendingChecks)
|
720 | 721 |
|
721 | 722 | m_PendingChecks++;
|
722 | 723 | }
|
| 724 | + |
| 725 | +/** |
| 726 | + * Returns a random factor derived from scheduler_shuffle_cap to multiply the check interval with. |
| 727 | + * |
| 728 | + * E.g. if scheduler_shuffle_cap is 20 (%), this function returns [0.8, 1.2]. |
| 729 | + */ |
| 730 | +double Checkable::GetIntervalShuffleFactor() |
| 731 | +{ |
| 732 | + if (!GetEnableActiveChecks()) { |
| 733 | + // scheduler_shuffle_cap doesn't influence external checkers. |
| 734 | + return 1; |
| 735 | + } |
| 736 | + |
| 737 | + return (GetSchedulerShuffleCap() / 100) // scheduler_shuffle_cap as non-%, i.e. 10 => 0.1 |
| 738 | + * (rand() / (double)RAND_MAX * 2 - 1) // random number [-1, 1] |
| 739 | + + 1; |
| 740 | +} |
0 commit comments