Skip to content

Commit 7b049ba

Browse files
committed
graph: Explain how and why we initialize timestamps in KillState::new
1 parent 9422ec6 commit 7b049ba

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

graph/src/data/graphql/effort.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,19 @@ struct KillState {
149149

150150
impl KillState {
151151
fn new() -> Self {
152-
let long_ago = Duration::from_secs(60);
153-
let now = Instant::now();
154-
let before = now.checked_sub(long_ago).unwrap_or(now);
152+
// Set before to an instant long enough ago so that we don't
153+
// immediately log or adjust the kill rate if the node is already
154+
// under load. Unfortunately, on OSX, `Instant` measures time from
155+
// the last boot, and if that was less than 60s ago, we can't
156+
// subtract 60s from `now`. Since the worst that can happen if
157+
// we set `before` to `now` is that we might log more than strictly
158+
// necessary, and adjust the kill rate one time too often right after
159+
// node start, it is acceptable to fall back to `now`
160+
let before = {
161+
let long_ago = Duration::from_secs(60);
162+
let now = Instant::now();
163+
now.checked_sub(long_ago).unwrap_or(now)
164+
};
155165
Self {
156166
kill_rate: 0.0,
157167
last_update: before,

0 commit comments

Comments
 (0)