Prove the steady cost by count, redraw the bootstrap once a minute, tidy
A test fills a history with a row a minute for thirty days (43,199 rows, 4,319 build observations) in one transaction, runs two polls and asserts the second hands out fewer than 3,000 rows; it measures 1,567 (the first reads every observation once). History::fill saves a run of readings as the polls would have. While a build keeps adding observations, they are stored at once but the bootstrap and the histogram are redrawn at most once a minute. A saving is never negative or a negative zero. History::rows and History::build_observations are gone, with the tests that only used them. History::first_row stays: without it the chart of the reset range, on a database that never saw a zeroing, would start at the live reading instead of at the first row. The timing line is logged for the first two polls.
This commit is contained in:
1 parent
7ab1543315
commit
693dca6cdf
4 files changed
+270
-96
No files matched your search
@@ -28,6 +28,9 @@ pub mod levels {
|
||||
pub const RUNNING_WINDOW: Duration = Duration::from_secs(5 * 60);
|
||||
/// The chart has at most this many buckets.
|
||||
pub const BUCKETS: i64 = 120;
|
||||
/// The build-time bootstrap is drawn again at most this often, however many observations
|
||||
/// a build in flight keeps adding.
|
||||
pub const BOOTSTRAP_EVERY_SECS: i64 = 60;
|
||||
/// While anything changes a row comes at least this often, so a bucket with no row between
|
||||
/// two rows further apart than this is a gap.
|
||||
pub const GAP_SECS: i64 = 120;
|
||||
@@ -67,6 +70,8 @@ pub struct Builds {
|
||||
draws: Resampled,
|
||||
/// (how many observations there are, when the newest is dated) this was made from.
|
||||
stamp: Option<(i64, i64)>,
|
||||
/// When the bootstrap was last drawn.
|
||||
drawn_at: Option<i64>,
|
||||
}
|
||||
|
||||
impl Default for Builds {
|
||||
@@ -85,16 +90,25 @@ impl Builds {
|
||||
means: Vec::new(),
|
||||
draws: Resampled::new(&[]),
|
||||
stamp: None,
|
||||
drawn_at: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Takes in any observations added since the last look, and when there are some works out
|
||||
/// the histograms and draws the bootstrap again: once per change, not once per range.
|
||||
pub fn refresh(&mut self, h: &History) {
|
||||
pub fn refresh(&mut self, h: &History, now: i64) {
|
||||
let stamp = soft(h.build_obs_stamp());
|
||||
if self.stamp == Some(stamp) {
|
||||
return;
|
||||
}
|
||||
// Observations were added, but the bootstrap was drawn less than a minute ago: they wait
|
||||
// for that beat, so that a build in flight does not have it redrawn on every poll.
|
||||
if self
|
||||
.drawn_at
|
||||
.is_some_and(|at| now - at < levels::BOOTSTRAP_EVERY_SECS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
let added = match self.stamp {
|
||||
// Rows were only added: read just those.
|
||||
Some((count, newest)) if stamp.0 > count && stamp.1 >= newest => {
|
||||
@@ -133,6 +147,7 @@ impl Builds {
|
||||
self.draws = Resampled::new(&obs);
|
||||
self.times = times;
|
||||
self.stamp = Some(stamp);
|
||||
self.drawn_at = Some(now);
|
||||
}
|
||||
|
||||
/// Time saved for one range's hits, from the draws already made.
|
||||
@@ -165,7 +180,9 @@ impl Builds {
|
||||
/// What one hit of this language saves on average, for the chart; `None` when the language
|
||||
/// is left out.
|
||||
fn saving(&self, language: &str, hit_read: f64) -> Option<f64> {
|
||||
Some((self.means[self.languages.iter().position(|l| l == language)?]? - hit_read).max(0.0))
|
||||
Some(positive(
|
||||
self.means[self.languages.iter().position(|l| l == language)?]? - hit_read,
|
||||
))
|
||||
}
|
||||
|
||||
/// How the figure was reached, in plain words with the numbers used.
|
||||
@@ -235,6 +252,15 @@ impl Builds {
|
||||
}
|
||||
}
|
||||
|
||||
/// A saving is never negative, and never a negative zero (which JSON would print as `-0.0`).
|
||||
fn positive(value: f64) -> f64 {
|
||||
if value > 0.0 {
|
||||
value
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a language has seen enough usable observations for its saving to be counted.
|
||||
fn counted(obs: &[Observation]) -> bool {
|
||||
obs.iter()
|
||||
@@ -626,9 +652,11 @@ fn compute(
|
||||
let hit_read = per(counters.ns[HIT_READ], t.hits).unwrap_or(0.0) / 1e3;
|
||||
let saved = builds.saved(&counters.langs, hit_read);
|
||||
let time_saved = TimeSaved {
|
||||
seconds: saved.seconds,
|
||||
seconds: positive(saved.seconds),
|
||||
hits_left_out: saved.hits_left_out,
|
||||
interval_90: saved.interval_90,
|
||||
interval_90: saved
|
||||
.interval_90
|
||||
.map(|(lo, hi)| (positive(lo), positive(hi))),
|
||||
note: builds.note(&counters.langs, hit_read, &saved),
|
||||
};
|
||||
let mut languages: Vec<Language> = counters
|
||||
@@ -706,6 +734,7 @@ mod tests {
|
||||
}
|
||||
|
||||
const LIVE: &str = include_str!("../../../fixtures/live-0.18.0.json");
|
||||
const NOW: i64 = 100_000;
|
||||
|
||||
/// A reading with these totals, all of it Rust, taking 1 s per hit read, 1 s per cache
|
||||
/// write and 60 s per compile.
|
||||
@@ -766,7 +795,7 @@ mod tests {
|
||||
});
|
||||
}
|
||||
let mut builds = Builds::new();
|
||||
builds.refresh(&history);
|
||||
builds.refresh(&history, NOW);
|
||||
Scene {
|
||||
history,
|
||||
builds,
|
||||
@@ -1121,7 +1150,7 @@ mod tests {
|
||||
..State::default()
|
||||
};
|
||||
let mut builds = Builds::new();
|
||||
builds.refresh(&history);
|
||||
builds.refresh(&history, NOW);
|
||||
let mut scene = Scene {
|
||||
history,
|
||||
builds,
|
||||
@@ -1160,6 +1189,62 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_range_saves_exactly_zero_never_a_negative_zero() {
|
||||
let c = |misses: u64| Counters {
|
||||
totals: Totals {
|
||||
requests: misses,
|
||||
misses,
|
||||
cache_writes: misses,
|
||||
..Totals::default()
|
||||
},
|
||||
compilations: misses,
|
||||
ns: [0, 0, misses * 60_000_000_000],
|
||||
langs: vec![("Rust".to_owned(), [0, misses, 0])],
|
||||
..Counters::default()
|
||||
};
|
||||
// Twelve polls after each of which one Rust build finished: enough to count Rust. Then a
|
||||
// live reading with no hit anywhere.
|
||||
let history = History::memory().unwrap();
|
||||
let mut tracker = Tracker::default();
|
||||
for step in 0..12u64 {
|
||||
history
|
||||
.record(&mut tracker, &c(step), (step * 10) as i64)
|
||||
.unwrap();
|
||||
}
|
||||
let live = Live {
|
||||
at: 130,
|
||||
snapshot: stats::Snapshot {
|
||||
counters: c(11),
|
||||
..Default::default()
|
||||
},
|
||||
raw_text: String::new(),
|
||||
};
|
||||
let state = State {
|
||||
tracker: history.tracker(),
|
||||
live: Some(live),
|
||||
..State::default()
|
||||
};
|
||||
let mut builds = Builds::new();
|
||||
builds.refresh(&history, 130);
|
||||
assert_eq!(builds.times[0].compiles, 11, "Rust is counted");
|
||||
|
||||
let views = all(&history, &builds, &state, 130);
|
||||
for (range, v) in Range::ALL.iter().zip(&views) {
|
||||
let ts = &v.time_saved;
|
||||
assert_eq!((ts.seconds, ts.hits_left_out), (0.0, 0), "{range:?}");
|
||||
assert!(!ts.seconds.is_sign_negative(), "{range:?}: {}", ts.seconds);
|
||||
let json = serde_json::to_string(ts).unwrap();
|
||||
assert!(!json.contains('-'), "{range:?}: no minus sign in {json}");
|
||||
assert!(
|
||||
v.buckets
|
||||
.iter()
|
||||
.all(|b| b.saved_seconds == 0.0 && !b.saved_seconds.is_sign_negative()),
|
||||
"{range:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn time_saved_is_zero_and_explained_when_nothing_is_learned() {
|
||||
let assembler = |hits: u64| Counters {
|
||||
|
||||
Reference in new issue
Block a user