Skip to content

graph: Fix an error in KillState::new #1806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions graph/src/data/graphql/effort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,24 @@ struct KillState {

impl KillState {
fn new() -> Self {
let long_ago = Duration::from_secs(86400);
// Set before to an instant long enough ago so that we don't
// immediately log or adjust the kill rate if the node is already
// under load. Unfortunately, on OSX, `Instant` measures time from
// the last boot, and if that was less than 60s ago, we can't
// subtract 60s from `now`. Since the worst that can happen if
// we set `before` to `now` is that we might log more than strictly
// necessary, and adjust the kill rate one time too often right after
// node start, it is acceptable to fall back to `now`
let before = {
let long_ago = Duration::from_secs(60);
let now = Instant::now();
now.checked_sub(long_ago).unwrap_or(now)
};
Self {
kill_rate: 0.0,
last_update: Instant::now() - long_ago,
last_update: before,
overload_start: None,
last_overload_log: Instant::now() - long_ago,
last_overload_log: before,
}
}

Expand Down