-
Notifications
You must be signed in to change notification settings - Fork 103
feat(pool): Expose utilization and activity metrics from the pool #4658
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
Changes from 15 commits
b5ef773
4468370
286990a
edeaf53
be35884
e3b2f86
797798d
22da49c
82c4da9
73072fc
a9690ce
fd812df
672ce99
929afc6
193d25a
b57ac80
d05cf09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
use relay_system::RawMetrics; | ||
use std::sync::atomic::{AtomicU64, Ordering}; | ||
use std::sync::Arc; | ||
|
||
|
@@ -13,6 +14,8 @@ pub(crate) struct ThreadMetrics { | |
/// | ||
/// This number will monotonically grow if not reset. | ||
pub(crate) finished_tasks: AtomicU64, | ||
/// The raw metrics collected by the timed future. | ||
pub(crate) raw_metrics: Arc<RawMetrics>, | ||
} | ||
|
||
impl ThreadMetrics { | ||
|
@@ -53,13 +56,40 @@ impl AsyncPoolMetrics<'_> { | |
} | ||
|
||
/// Returns the utilization metric for the pool. | ||
pub fn utilization(&self) -> f32 { | ||
/// | ||
/// The utilization is measured as the amount of busy work performed by each thread when polling | ||
/// the futures. | ||
/// | ||
/// A utilization of 100% indicates that the pool has been doing CPU-bound work for the duration | ||
/// of the measurement. | ||
/// A utilization of 0% indicates that the pool didn't do any CPU-bound work for the duration | ||
/// of the measurement. | ||
/// | ||
/// Note that this metric is collected and updated for each thread when the main future is polled, | ||
/// thus if no work is being done, it will not be updated. | ||
pub fn utilization(&self) -> u8 { | ||
|
||
self.threads_metrics | ||
.iter() | ||
.map(|m| m.raw_metrics.utilization.load(Ordering::Relaxed)) | ||
.max() | ||
.unwrap_or(100) | ||
} | ||
|
||
/// Returns the activity metric for the pool. | ||
/// | ||
/// The activity is measure as the amount of active tasks in the pool versus the maximum amount | ||
/// of tasks that the pool can have active at the same time. | ||
/// | ||
/// An activity of 100% indicates that the pool is driving the maximum number of tasks that it | ||
/// can. | ||
/// An activity of 0% indicates that the pool is not driving any tasks. | ||
pub fn activity(&self) -> u8 { | ||
let total_polled_futures: u64 = self | ||
.threads_metrics | ||
.iter() | ||
.map(|m| m.active_tasks.load(Ordering::Relaxed)) | ||
.sum(); | ||
|
||
(total_polled_futures as f32 / self.max_tasks as f32).clamp(0.0, 1.0) * 100.0 | ||
(total_polled_futures as f32 / self.max_tasks as f32).clamp(0.0, 1.0) as u8 * 100 | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.