Skip to content

Commit

Permalink
Add random sleep interval to FetchList worker to reduce server load
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed Dec 4, 2024
1 parent 41d347a commit e947d21
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Probe/Jobs/Monitor/FetchList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export default class FetchListAndProbe {
// eslint-disable-next-line no-constant-condition
while (true) {
try {
// Sleep randomly between 1 and 5 seconds.
// We do this to avoid all workers hitting the server at the same time and fetching the same monitors.
const sleepTime: number = Math.floor(Math.random() * 5000) + 1000;
logger.debug(
`Worker ${this.workerName} is sleeping for ${sleepTime} seconds`,
);
await Sleep.sleep(Math.round(sleepTime) % 5000);

const runTime: Date = OneUptimeDate.getCurrentDate();

logger.debug(`Probing monitors ${this.workerName}`);
Expand Down

0 comments on commit e947d21

Please sign in to comment.