|
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")
|
@@ -372,7 +373,7 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
|
372 | 373 | if (ttl > 0)
|
373 | 374 | offset = ttl;
|
374 | 375 | else
|
375 |
| - offset = GetCheckInterval(); |
| 376 | + offset = GetCheckInterval() * GetIntervalShuffleFactor(); |
376 | 377 |
|
377 | 378 | SetNextCheck(Utility::GetTime() + offset, false, origin);
|
378 | 379 | }
|
@@ -412,7 +413,7 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
|
412 | 413 | if (!parent->GetEnableActiveChecks())
|
413 | 414 | continue;
|
414 | 415 |
|
415 |
| - if (parent->GetNextCheck() >= now + parent->GetRetryInterval()) { |
| 416 | + if (parent->GetNextCheck() >= now + parent->GetRetryInterval() * parent->GetIntervalShuffleFactor()) { |
416 | 417 | ObjectLock olock(parent);
|
417 | 418 | parent->SetNextCheck(now);
|
418 | 419 | }
|
@@ -707,3 +708,20 @@ void Checkable::AquirePendingCheckSlot(int maxPendingChecks)
|
707 | 708 |
|
708 | 709 | m_PendingChecks++;
|
709 | 710 | }
|
| 711 | + |
| 712 | +/** |
| 713 | + * Returns a random factor derived from scheduler_shuffle_cap to multiply the check interval with. |
| 714 | + * |
| 715 | + * E.g. if scheduler_shuffle_cap is 20 (%), this function returns [0.8, 1.2]. |
| 716 | + */ |
| 717 | +double Checkable::GetIntervalShuffleFactor() |
| 718 | +{ |
| 719 | + if (!GetEnableActiveChecks()) { |
| 720 | + // scheduler_shuffle_cap doesn't influence external checkers. |
| 721 | + return 1; |
| 722 | + } |
| 723 | + |
| 724 | + return (GetSchedulerShuffleCap() / 100) // scheduler_shuffle_cap as non-%, i.e. 10 => 0.1 |
| 725 | + * (rand() / (double)RAND_MAX * 2 - 1) // random number [-1, 1] |
| 726 | + + 1; |
| 727 | +} |
0 commit comments