-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
stabilize worker_total_busy_duration #6899
base: master
Are you sure you want to change the base?
stabilize worker_total_busy_duration #6899
Conversation
…ch and Histogram out of unstable flag
/// Whether the histogram used to aggregate a metric uses a linear or | ||
/// logarithmic scale. | ||
#[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
#[non_exhaustive] | ||
#[allow(unreachable_pub)] | ||
pub enum HistogramScale { | ||
/// Linear bucket scale | ||
Linear, | ||
|
||
/// Logarithmic bucket scale | ||
#[allow(dead_code)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this change required for the mean time stabilization or just a coincidental change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this change is required.
At master we have implemented another struct WorkerMetrics
at tokio/src/runtime/metrics/mock.rs
which didn't use struct Histogram
defined at tokio/src/runtime/metrics/histogram.rs
.
In order to stabilize the API, I have to removed this mock WorkerMetrics and instead point to the "real" WorkerMetrics
at tokio/src/runtime/metrics/worker.rs
The "real" WorkerMetrics
has a field poll_count_histogram
which is Option<Histogram>
, and thus will attempt to parse tokio/src/runtime/metrics/histogram.rs
. From there, you can see Histogram and HistogramBuilder both refers to HistogramScale
which is hidden inside tokio_unstable
. I think this wouldn't compile.
(I might be wrong though so feel free to correct me)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to read through this PR in more detail so bare with me, but we shouldn't be making this stable and public if it isn't actually needed to to stabilize worker_total_busy_duration
(and I'm mostly sure that it isn't).
In general, all the #[allow(dead_code)]
that are required for this chnage give me the impression that we're exposing something that is only really used in tokio_unstable
and so we should find a way to expose it only unstable tokio_unstable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comment!
I think the core issue here is that by exposing worker_total_busy_duration
, we are also exposing the "real" WorkerMetrics
at tokio/src/runtime/metrics/worker.rs
, which in turn will attempt to parse HistogramScale
.
Currently at master branch, when no tokio_unstable
flag is passed in, the WorkerMetrics
at tokio/src/runtime/metrics/mock.rs
will be parsed (which is just an empty struct). And if the flag is passed in, the WorkerMetrics
at tokio/src/runtime/metrics/worker.rs
will be parsed
https://github.com/tokio-rs/tokio/blob/master/tokio/src/runtime/metrics/mod.rs#L27-L40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not actually public, it's still behind config_unstable. (Just verified via the autogenerated docs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah becoz HistogramScale
is still behind cfg_unstable_metrics
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, now I believe I understand.
I would suggest that instead of compiling with the entire worker metrics in order to access only the busy_duration_total
field, we should gate all the fields that we won't be using on cfg_unstable_metrics
. Otherwise users will still be paying the price for metrics which they don't have access to - and that is something that we would really like to avoid.
Have a look at the runtime Builder for an example of how we have fields and implementations that touch them gated on a cfg flag:
tokio/tokio/src/runtime/builder.rs
Lines 125 to 126 in 512e9de
#[cfg(tokio_unstable)] | |
pub(super) unhandled_panic: UnhandledPanic, |
As a general rule, if you need #[allow(dead_code)]
then there is probably something that should be gated on a cfg flag instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hds . I've reverted changes to histogram.rs
. Also the real Histogram
, HistogramBuilder
and HistogramBatch
are gated behind unstable flag now, and instead I've created a mocked version of these for compilation.
For WorkerMetrics
, as we target to stabilize more metrics, I'd suggest exposing all fields instead of stabilizing only busy_duration_total
and putting other fields behind unstable.
Let me know what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Owen-CH-Leung the problem with stabilizing all of WorkerMetrics
is that when tokio_unstable
is not enabled, the runtime will pay the price for all those metrics, but there will be no way to access them. For this reason I think that it would be better to only stabilize what we're exposing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hds . I've made changes to hide most of the fields of WorkerMetrics
behind unstable flag, except for busy_duration_total
, queue_depth
and thread_id
. The latter 2 fields are needed in order for set_queue_depth
and set_thread_id
to work properly.
I've also enriched the mock MetricsBatch
to have minimal implementation of batch::MetricsBatch
so that the worker_total_busy_duration
API can function properly under stable build
Let me know your thoughts!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please bare with me as I haven't finished the review, but my first impression is that this PR is making more things public than is strictly necessary for the stabilization of worker_total_busy_duration
and we should try to avoid that.
This is especially true since #6897 is also touching the histogram (although not taking it out of tokio_unstable
) and that would be a breaking change if this PR is released first.
/// Whether the histogram used to aggregate a metric uses a linear or | ||
/// logarithmic scale. | ||
#[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
#[non_exhaustive] | ||
#[allow(unreachable_pub)] | ||
pub enum HistogramScale { | ||
/// Linear bucket scale | ||
Linear, | ||
|
||
/// Logarithmic bucket scale | ||
#[allow(dead_code)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to read through this PR in more detail so bare with me, but we shouldn't be making this stable and public if it isn't actually needed to to stabilize worker_total_busy_duration
(and I'm mostly sure that it isn't).
In general, all the #[allow(dead_code)]
that are required for this chnage give me the impression that we're exposing something that is only really used in tokio_unstable
and so we should find a way to expose it only unstable tokio_unstable
.
…nges on histogram.rs and guard it behind unstable flag
…on_total, queue_depth and thread_id
@@ -533,7 +533,7 @@ impl Handle { | |||
self.shared.inject.len() | |||
} | |||
|
|||
#[allow(dead_code)] | |||
// #[allow(dead_code)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// #[allow(dead_code)] |
@@ -18,7 +18,7 @@ impl Handle { | |||
self.shared.injection_queue_depth() | |||
} | |||
|
|||
#[allow(dead_code)] | |||
// #[allow(dead_code)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// #[allow(dead_code)] |
tokio/src/runtime/metrics/worker.rs
Outdated
.as_ref() | ||
.map(|histogram_builder| histogram_builder.build()); | ||
worker_metrics | ||
cfg_unstable_metrics! { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better if we grouped all the unstable functions together at the bottom of the impl
block, instead of spreading them out.
tokio/src/runtime/metrics/worker.rs
Outdated
@@ -15,40 +18,60 @@ use std::thread::ThreadId; | |||
#[derive(Debug, Default)] | |||
#[repr(align(128))] | |||
pub(crate) struct WorkerMetrics { | |||
#[cfg(tokio_unstable)] | |||
#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? Since this isn't a public method, it won't appear in the documentation.
tokio/src/runtime/metrics/mock.rs
Outdated
} | ||
|
||
pub(crate) fn submit(&mut self, _to: &WorkerMetrics, _mean_poll_time: u64) {} | ||
pub(crate) fn submit(&mut self, worker: &WorkerMetrics, _mean_poll_time: u64) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand correctly that this function duplicates part of the submit
function in batch::MetricsBatch
?
I think this is a problematic way of gradually stabilizing metrics, as it opens the possibility of having divirging implementations if a change is made to the "real" MetricsBatch
by someone who doesn't realise that there is another one.
This is additionally confusing because this effectively becomes the "stable" implementation, but it lives in a module called mock
.
I would propose that we instead split the metrics::MetricsBatch
implementation into stable (always compiles) and unstable (gated by cfg
option), the same way we've done elsewhere in this PR. The same as with another comment, we would group all the unstable functions into a single cfg_unstable_metrics!
block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed spliting metrics::MetricsBatch
is a much viable way of stabilising. I've adopted your suggestion and split it into stable & unstable (and group unstable functions into a single unstable block. Thanks a lot for reviewing!
Motivation
Stabilize worker_total_busy_duration so it can be used outside of --cfg tokio_unstable
Solution
Move the API impl out of tokio_unstable flag
Ref: #6546