2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-22 03:11:24 +00:00

Reduce poll timer sampling from ~100% to ~10%

This should improve performance just a little bit
This commit is contained in:
asonix 2024-12-09 19:14:46 -06:00
parent 04bde6cf20
commit 8a551fa65d

View file

@ -141,50 +141,54 @@ where
let out = this.inner.poll(cx); let out = this.inner.poll(cx);
let elapsed = start.elapsed(); let elapsed = start.elapsed();
if elapsed > Duration::from_micros(10) {
metrics::counter!(crate::init_metrics::FUTURE_POLL_TIMER_EXCEEDED, "timer" => this.name.to_string()).increment(1);
metrics::histogram!(crate::init_metrics::FUTURE_POLL_TIMER_EXCEEDED_SECONDS, "timer" => this.name.to_string()).record(elapsed.as_secs_f64());
}
if elapsed > Duration::from_secs(1) { // only record 1 in 10 polls
#[cfg(feature = "poll-timer-warnings")] if elapsed.as_micros() % 10 == 0 {
tracing::warn!( if elapsed > Duration::from_micros(10) {
"Future {} polled for {} seconds", metrics::counter!(crate::init_metrics::FUTURE_POLL_TIMER_EXCEEDED, "timer" => this.name.to_string()).increment(1);
this.name, metrics::histogram!(crate::init_metrics::FUTURE_POLL_TIMER_EXCEEDED_SECONDS, "timer" => this.name.to_string()).record(elapsed.as_secs_f64());
elapsed.as_secs() }
);
#[cfg(not(feature = "poll-timer-warnings"))] if elapsed > Duration::from_secs(1) {
tracing::debug!( #[cfg(feature = "poll-timer-warnings")]
"Future {} polled for {} seconds", tracing::warn!(
this.name, "Future {} polled for {} seconds",
elapsed.as_secs() this.name,
); elapsed.as_secs()
} else if elapsed > Duration::from_millis(1) { );
#[cfg(feature = "poll-timer-warnings")]
tracing::warn!("Future {} polled for {} ms", this.name, elapsed.as_millis());
#[cfg(not(feature = "poll-timer-warnings"))] #[cfg(not(feature = "poll-timer-warnings"))]
tracing::debug!("Future {} polled for {} ms", this.name, elapsed.as_millis()); tracing::debug!(
} else if elapsed > Duration::from_micros(200) { "Future {} polled for {} seconds",
#[cfg(feature = "poll-timer-warnings")] this.name,
tracing::debug!( elapsed.as_secs()
"Future {} polled for {} microseconds", );
this.name, } else if elapsed > Duration::from_millis(1) {
elapsed.as_micros(), #[cfg(feature = "poll-timer-warnings")]
); tracing::warn!("Future {} polled for {} ms", this.name, elapsed.as_millis());
#[cfg(not(feature = "poll-timer-warnings"))]
tracing::trace!( #[cfg(not(feature = "poll-timer-warnings"))]
"Future {} polled for {} microseconds", tracing::debug!("Future {} polled for {} ms", this.name, elapsed.as_millis());
this.name, } else if elapsed > Duration::from_micros(200) {
elapsed.as_micros(), #[cfg(feature = "poll-timer-warnings")]
); tracing::debug!(
} else if elapsed > Duration::from_micros(1) { "Future {} polled for {} microseconds",
tracing::trace!( this.name,
"Future {} polled for {} microseconds", elapsed.as_micros(),
this.name, );
elapsed.as_micros() #[cfg(not(feature = "poll-timer-warnings"))]
); tracing::trace!(
"Future {} polled for {} microseconds",
this.name,
elapsed.as_micros(),
);
} else if elapsed > Duration::from_micros(1) {
tracing::trace!(
"Future {} polled for {} microseconds",
this.name,
elapsed.as_micros()
);
}
} }
out out