Prevent devices always being pinged at exactly the same time (#6133)

* Add availability lag of rand 10% from timeout

* Update availability.js

* Update utils.js

Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
This commit is contained in:
Andrew Ostroumov
2021-02-14 11:37:31 +01:00
committed by GitHub
co-authored by Koen Kanters
parent 1b76cd0ae5
commit 1df52cc6e8
2 changed files with 11 additions and 2 deletions
+2 -1
View File
@@ -3,6 +3,7 @@
.git
.github
.gitignore
.idea
.npmrc
.travis*
.travis.yml
@@ -12,4 +13,4 @@ images
node_modules
scripts
test
update.sh
update.sh
+9 -1
View File
@@ -14,6 +14,13 @@ const pingableEndDevices = [
];
const Hours25 = 1000 * 60 * 60 * 25;
const AvailabilityLagRatio = 0.1;
function timeoutLag(timeout, ratio) {
const lag = timeout * ratio;
return Math.floor(Math.random() * Math.floor(lag));
}
/**
* This extensions pings devices to check if they are online.
@@ -137,10 +144,11 @@ class Availability extends Extension {
}
setTimerPingable(device) {
const timeout = this.availability_timeout + timeoutLag(this.availability_timeout, AvailabilityLagRatio);
clearTimeout(this.timers[device.ieeeAddr]);
this.timers[device.ieeeAddr] = setTimeout(async () => {
await this.handleIntervalPingable(device);
}, utils.secondsToMilliseconds(this.availability_timeout));
}, utils.secondsToMilliseconds(timeout));
}
async stop() {