Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Speed up timestamp generation when logging #9933

Merged
3 commits merged into from
Oct 5, 2021

Conversation

koute
Copy link
Contributor

@koute koute commented Oct 5, 2021

This PR speeds up how we generate timestamps when logging; instead of regenerating them from scratch all the time we now cache part of the timestamp in TLS.

Here's the performance of the original implementation as measured on my machine:

chrono_local            time:   [871.11 ns 872.19 ns 873.30 ns] 

And here's the performance of the new one:

fast_local_time         time:   [35.994 ns 36.011 ns 36.030 ns]

So the overhead was cut down to less than 10%.

Seems like this was pretty cheap in the first place; does this actually matter?

This will not help in normal cases where we're not logging much, but anytime someone turns on a spammy trace log (which does happen on our staking ops' nodes) the costs of logging starts to balloon. Yes, we shouldn't be logging this much. But if we do then it shouldn't bog down the CPU as much as it does.

Even though this might seem like it shouldn't make much difference the issue here is that at this scale we're experiencing a case of a death by a thousand cuts, where even though doing it only once is very cheap we're doing it so much that once you add everything together you end up in a situation where logging can take a whopping 30% of the total CPU time. This is one of the easier and most straightforward improvements we can make, which represented ~6.6% of the total CPU used in this particular profiling run, which now should be cut down to less than ~1%.

@koute koute added A0-please_review Pull request needs code review. I9-optimisation An enhancement to provide better overall performance in terms of time-to-completion for a task. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Oct 5, 2021
@koute koute requested a review from gilescope October 5, 2021 06:28
@koute koute added the D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit label Oct 5, 2021
Copy link
Contributor

@gilescope gilescope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work.

@gilescope gilescope requested a review from bkchr October 5, 2021 09:26
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimization!

client/tracing/src/logging/fast_local_time.rs Outdated Show resolved Hide resolved
client/tracing/src/logging/fast_local_time.rs Outdated Show resolved Hide resolved
client/tracing/src/logging/fast_local_time.rs Outdated Show resolved Hide resolved
client/tracing/src/logging/fast_local_time.rs Outdated Show resolved Hide resolved
client/tracing/src/logging/fast_local_time.rs Outdated Show resolved Hide resolved
client/tracing/benches/bench.rs Outdated Show resolved Hide resolved
@koute
Copy link
Contributor Author

koute commented Oct 5, 2021

bot merge

@ghost
Copy link

ghost commented Oct 5, 2021

Trying merge.

@ghost ghost merged commit ddf8992 into paritytech:master Oct 5, 2021
ordian added a commit that referenced this pull request Oct 5, 2021
* master: (125 commits)
  Update multiple dependencies (#9936)
  Speed up timestamp generation when logging (#9933)
  First word should be Substrate not Polkadot (#9935)
  Improved file not found error message (#9931)
  don't read events in elections anymore. (#9898)
  Remove incorrect sanity check (#9924)
  Require crypto scheme for `insert-key` (#9909)
  chore: refresh of the substrate_builder image (#9808)
  Introduce block authorship soft deadline (#9663)
  Rework Transaction Priority calculation (#9834)
  Do not propagate host RUSTFLAGS when checking for WASM toolchain (#9926)
  Small quoting comment fix (#9927)
  add clippy to CI (#9694)
  Ensure BeforeBestBlockBy voting rule accounts for base (#9920)
  rm `.maintain` lock (#9919)
  Downstream `node-template` pull (#9915)
  Implement core::fmt::Debug for BoundedVec (#9914)
  Quickly skip invalid transactions during block authorship. (#9789)
  Add SS58 prefix for Automata (#9805)
  Clean up sc-peerset (#9806)
  ...
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit I9-optimisation An enhancement to provide better overall performance in terms of time-to-completion for a task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants