Skip to content

Commit

Permalink
fix(log): avoid divide by zero in log info (#2514)
Browse files Browse the repository at this point in the history
#2472 is supposed to make log summary run regularly and not get blocked by something else on the event loop. However, it didn't actually achieve that. What's worse, I think it caused the correct number of calls to be scheduled, but not executed at the same time. When the event loop is busy, it can end up executing 10 calls at the same time, which results in the confusing logs:
```
Apr 22 05:37:57.914  INFO stats: # 3166239 Downloading headers 48% -/10  6/6/40 peers ⬇ 11.7kiB/s ⬆ 22 B/s 0.00 bps 0 gas/s CPU: 110%, Mem: 50.2 MiB    
Apr 22 05:37:57.915  INFO stats: # 3166239 Downloading headers 48% -/10  6/6/40 peers ⬇ 11.7kiB/s ⬆ 22 B/s 0.00 bps 0 gas/s CPU: NaN%, Mem: 50.2 MiB    
Apr 22 05:37:57.916  INFO stats: # 3166239 Downloading headers 48% -/10  6/6/40 peers ⬇ 11.7kiB/s ⬆ 22 B/s NaN bps 9223372.04 Tgas/s CPU: NaN%, Mem: 50.2 MiB    
Apr 22 05:38:48.839  INFO stats: # 3166239 Downloading headers 48% -/10  7/7/40 peers ⬇ 26.1kiB/s ⬆ 1.8kiB/s 0.00 bps 0 gas/s CPU: 108%, Mem: 52.5 MiB    
Apr 22 05:38:48.840  INFO stats: # 3166239 Downloading headers 48% -/10  7/7/40 peers ⬇ 26.1kiB/s ⬆ 1.8kiB/s NaN bps 9223372.04 Tgas/s CPU: NaN%, Mem: 52.5 MiB
```
This is because time elapsed between two `log_summary` calls is less than one millisecond and it causes some divide by zero errors. This PR therefore reverts the change in #2472.

Test plan
---------
Run a node locally to see that there is no more `NaN`s.
  • Loading branch information
bowenwang1996 authored Apr 27, 2020
1 parent 1aea93d commit 38d54ba
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion chain/client/src/client_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ impl ClientActor {

/// Periodically log summary.
fn log_summary(&self, ctx: &mut Context<Self>) {
ctx.run_interval(self.client.config.log_summary_period, move |act, _ctx| {
ctx.run_later(self.client.config.log_summary_period, move |act, ctx| {
let head = unwrap_or_return!(act.client.chain.head());
let validators = unwrap_or_return!(act
.client
Expand Down Expand Up @@ -1178,6 +1178,8 @@ impl ClientActor {
is_fishermen,
num_validators,
);

act.log_summary(ctx);
});
}
}

0 comments on commit 38d54ba

Please sign in to comment.