Skip to content

Commit

Permalink
dashboard: optimize RateTracker by not changing the array length; ave…
Browse files Browse the repository at this point in the history
…rage the rate over 3 sec and remove the cap on the number of readings
  • Loading branch information
ivan committed Jun 9, 2023
1 parent 87a3c95 commit e5bf5a4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions dashboard/assets/scripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -936,9 +936,10 @@ class Decayer {

class RateTracker {
constructor(keepReadings) {
this.keepReadings = keepReadings;
this._durations = [];
this._values = [];
this._idx = 0;
this._durations = new Array(keepReadings).fill(0);
this._values = new Array(keepReadings).fill(0);
this._keepReadings = keepReadings;
this._reset();
}

Expand All @@ -947,12 +948,11 @@ class RateTracker {
}

_addReading(duration, value) {
this._durations.push(duration);
this._values.push(value);
if (this._durations.length > this.keepReadings) {
this._durations.shift();
this._values.shift();
}
const idx = this._idx;
this._durations[idx] = duration;
this._values[idx] = value;
// Loop back to 0 when we reach the end
this._idx = (idx + 1) % this._keepReadings;
}

getRate(value) {
Expand Down Expand Up @@ -1043,7 +1043,7 @@ class Dashboard {
const finishSetup = () => {
byId("meta-info").innerHTML = "";

const keepReadings = Math.min(31, Math.round(2000 / batchTimeWhenVisible));
const keepReadings = Math.round(3000 / batchTimeWhenVisible);
const messagesRate = new RateTracker(keepReadings);
const bytesRate = new RateTracker(keepReadings);

Expand Down

0 comments on commit e5bf5a4

Please sign in to comment.