Skip to content
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

metrics: Improve flexibility of H2Histogram Configuration #6963

Merged
merged 3 commits into from
Jan 8, 2025

Conversation

rcoh
Copy link
Contributor

@rcoh rcoh commented Nov 8, 2024

Motivation

Based on feedback #6960, customers want more flexibility in histogram configuration.

The main change here is allowing precision for an H2 Histgoram to go all the way down to zero—there is not fundamental reason this wasn't possible before, but typically H2 histograms stop at P=2.

Solution

I've also added another optimization that truncates the number of buckets based on the requested max_value. This can save space by truncating in the middle of a bucket group.

Along the way and in the process of adding more tests, I found a couple of bugs which are fixed here:

  1. The max_value in LogHistogramBuilder wasn't precisely respected
  2. The max_value computed by LogHistogram was actually incorrect for some n/p combinations. The new version precisely considers bucket layout instead.

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-metrics Module: tokio/runtime/metrics labels Nov 8, 2024
for b in 0..num_buckets {
let range = metrics.poll_time_histogram_bucket_range(b);
let size = range.end - range.start;
println!("bucket {b}: {range:?} (size: {size:?})");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we assert their values here instead of printing?

panic!("precision must be >= 2");
};
if p > 10 {
if p > MAX_PRECISION {
panic!("precision must be <= 10");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
panic!("precision must be <= 10");
panic!("precision must be <= {}", MAX_PRECISION);

Comment on lines 167 to 169
/// To match the behavior of the previous log histogram implementation, use
/// `builder.precision_exact(0)`. This creates a histogram where each bucket is twice the size
/// of the previous value.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd revert the order of this sentence so you first say that passing 0 results in buckets with doubling being used for the size, and then you can comment that this matches the behavior used in the legacy implementation.

@@ -1245,8 +1245,30 @@ impl Builder {
/// .unwrap();
/// ```
///
/// Configure a `LogHistogram` with similar behavior to [`HistogramScale::Log`]
Copy link
Contributor

Choose a reason for hiding this comment

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

This sentence is confusing. I'm guessing HistogramScale::Log is the old implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes clarified

Comment on lines 1249 to 1250
/// ```rust
///
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// ```rust
///
/// ```rust

@Darksonn
Copy link
Contributor

Any status update on this?

@rcoh
Copy link
Contributor Author

rcoh commented Nov 21, 2024 via email

@hds
Copy link
Contributor

hds commented Nov 21, 2024

@rcoh:

Sorry I went on parental leave

Congratulations!!

@rcoh rcoh force-pushed the allow-p-0 branch 2 times, most recently from 009d531 to eaffd4b Compare November 25, 2024 15:25
@rcoh
Copy link
Contributor Author

rcoh commented Dec 15, 2024

This is ready btw @Darksonn

@Darksonn
Copy link
Contributor

@hds or @Noah-Kennedy can you review?

@Noah-Kennedy
Copy link
Contributor

I'll review today

@Noah-Kennedy
Copy link
Contributor

I'd like @hds to take a look actually here, as I have not been involved with the histogram too much.

Copy link
Contributor

@hds hds left a comment

Choose a reason for hiding this comment

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

This is good from my side, but there are still a couple of comments from @Darksonn which I think haven't been addressed.

rcoh and others added 3 commits December 26, 2024 15:25
Based on feedback tokio-rs#6960, customers want more flexibility in histogram configuration. The main change here is allowing precision for an H2 Histgoram to go all the way down to zero—there is not fundamental reason this wasn't possible before, but typically H2 histograms stop at P=2.

I've also added another optimization that truncates the number of buckets based on the requested max_value. This can save space by truncating in the middle of a bucket group.

Along the way and in the process of adding more tests, I found a couple of bugs which are fixed here:
1. The `max_value` in LogHistogramBuilder wasn't precisely respected
2. The `max_value` computed by `LogHistogram` was actually incorrect for some n/p combinations. The new version precisely considers bucket layout instead.
@Darksonn
Copy link
Contributor

Darksonn commented Jan 4, 2025

I'll review this once I'm back from vacation next week. :)

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thanks.

@Darksonn Darksonn merged commit 15495fd into tokio-rs:master Jan 8, 2025
81 checks passed
kodiakhq bot pushed a commit to pdylanross/fatigue that referenced this pull request Jan 13, 2025
⚠️  Dependabot is rebasing this PR ⚠️
Rebasing might not happen immediately, so don't worry if this takes some time.
Note: if you make any changes to this PR yourself, they will take precedence over the rebase.

Bumps tokio from 1.42.0 to 1.43.0.

Release notes
Sourced from tokio's releases.

Tokio v1.43.0
1.43.0 (Jan 8th, 2025)
Added

net: add UdpSocket::peek methods (#7068)
net: add support for Haiku OS (#7042)
process: add Command::into_std() (#7014)
signal: add SignalKind::info on illumos (#6995)
signal: add support for realtime signals on illumos (#7029)

Fixed

io: don't call set_len before initializing vector in Blocking (#7054)
macros: suppress clippy::needless_return in #[tokio::main] (#6874)
runtime: fix thread parking on WebAssembly (#7041)

Changes

chore: use unsync loads for unsync_load (#7073)
io: use Buf::put_bytes in Repeat read impl (#7055)
task: drop the join waker of a task eagerly (#6986)

Changes to unstable APIs

metrics: improve flexibility of H2Histogram Configuration (#6963)
taskdump: add accessor methods for backtrace (#6975)

Documented

io: clarify ReadBuf::uninit allows initialized buffers as well (#7053)
net: fix ambiguity in TcpStream::try_write_vectored docs (#7067)
runtime: fix LocalRuntime doc links (#7074)
sync: extend documentation for watch::Receiver::wait_for (#7038)
sync: fix typos in OnceCell docs (#7047)

#6874: tokio-rs/tokio#6874
#6963: tokio-rs/tokio#6963
#6975: tokio-rs/tokio#6975
#6986: tokio-rs/tokio#6986
#6995: tokio-rs/tokio#6995
#7014: tokio-rs/tokio#7014
#7029: tokio-rs/tokio#7029
#7038: tokio-rs/tokio#7038
#7041: tokio-rs/tokio#7041
#7042: tokio-rs/tokio#7042
#7047: tokio-rs/tokio#7047
#7053: tokio-rs/tokio#7053
#7054: tokio-rs/tokio#7054
#7055: tokio-rs/tokio#7055


... (truncated)


Commits

5f3296d chore: prepare Tokio v1.43.0 (#7079)
cc974a6 chore: prepare tokio-macros v2.5.0 (#7078)
15495fd metrics: improve flexibility of H2Histogram Configuration (#6963)
ad41834 io: don't call set_len before initializing vector in Blocking (#7054)
bd3e857 runtime: move is_join_waker_set assertion in unset_waker (#7072)
15f7366 runtime: fix LocalRuntime doc links (#7074)
fd2048d ci: split miri jobs into unit and integration tests (#7071)
e8f3915 chore: use unsync loads for unsync_load (#7073)
67f1277 net: fix ambiguity in TcpStream::try_write_vectored docs (#7067)
463502c io: clarify ReadBuf::uninit allows initialized buffers as well (#7053)
Additional commits viewable in compare view




Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

@dependabot rebase will rebase this PR
@dependabot recreate will recreate this PR, overwriting any edits that have been made to it
@dependabot merge will merge this PR after your CI passes on it
@dependabot squash and merge will squash and merge this PR after your CI passes on it
@dependabot cancel merge will cancel a previously requested merge and block automerging
@dependabot reopen will reopen this PR if it is closed
@dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
@dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
@dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-metrics Module: tokio/runtime/metrics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants