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
+156
-19
@@ -217,14 +217,15 @@ fn zero_from_the_dashboard_zeroes_sccache_and_keeps_the_history() {
|
||||
1,
|
||||
"the history stays, and the zeroing is one more row"
|
||||
);
|
||||
let row = &task.history.rows(0, i64::MAX).unwrap()[0];
|
||||
assert!(row.reset, "the zeroing shows in the history as a reset");
|
||||
assert!(
|
||||
task.history.last_reset().unwrap().is_some(),
|
||||
"the zeroing shows in the history as a reset"
|
||||
);
|
||||
assert_eq!(
|
||||
row.delta,
|
||||
stats::Counters::default(),
|
||||
task.history.sums(0, i64::MAX).unwrap(),
|
||||
Some(stats::Counters::default()),
|
||||
"nothing has been compiled since"
|
||||
);
|
||||
assert_eq!(task.history.last_reset().unwrap(), Some(row.t));
|
||||
|
||||
let v = app.view(Range::SinceReset);
|
||||
assert_eq!(
|
||||
@@ -331,10 +332,19 @@ fn rows_are_saved_when_counters_change_and_at_most_once_a_minute() {
|
||||
1,
|
||||
"a minute on, the change is saved"
|
||||
);
|
||||
let row = &task.history.rows(0, i64::MAX).unwrap()[0];
|
||||
assert_eq!(
|
||||
(row.t, row.delta.totals.requests, row.reset),
|
||||
(NOW + 60, 1, false)
|
||||
task.history
|
||||
.sums(0, i64::MAX)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.totals
|
||||
.requests,
|
||||
1
|
||||
);
|
||||
assert_eq!(
|
||||
task.history.last_reset().unwrap(),
|
||||
None,
|
||||
"a change is not a reset"
|
||||
);
|
||||
|
||||
task.poll(&app, NOW + 700);
|
||||
@@ -344,7 +354,7 @@ fn rows_are_saved_when_counters_change_and_at_most_once_a_minute() {
|
||||
"unchanged: nothing more is saved, however long the quiet lasts"
|
||||
);
|
||||
assert!(
|
||||
task.history.build_observations().unwrap().is_empty(),
|
||||
task.history.build_obs_stamp().unwrap() == (0, 0),
|
||||
"and with no misses there is no build observation"
|
||||
);
|
||||
assert_eq!(app.lock().views.len(), 5, "every poll makes the five views");
|
||||
@@ -380,9 +390,11 @@ fn the_history_survives_a_restart_in_its_file() {
|
||||
let mut c = b.clone();
|
||||
c.totals.requests += 5;
|
||||
history.record(&mut tracker, &c, NOW + 70).unwrap();
|
||||
let rows = history.rows(0, i64::MAX).unwrap();
|
||||
assert_eq!(rows.len(), 1);
|
||||
assert_eq!((rows[0].t, rows[0].delta.totals.requests), (NOW + 70, 5));
|
||||
assert_eq!(history.row_count().unwrap(), 1);
|
||||
assert_eq!(
|
||||
history.sums(0, i64::MAX).unwrap().unwrap().totals.requests,
|
||||
5
|
||||
);
|
||||
assert_eq!(
|
||||
app.view(Range::Day).range,
|
||||
Some(Range::Day),
|
||||
@@ -418,13 +430,12 @@ fn old_rows_are_deleted_at_startup() {
|
||||
1,
|
||||
"the one row older than 30 days"
|
||||
);
|
||||
let left: Vec<i64> = history
|
||||
.rows(0, i64::MAX)
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|r| r.t)
|
||||
.collect();
|
||||
assert_eq!(left, vec![NOW - 30 * day + 3600, NOW - 3600, NOW]);
|
||||
assert_eq!(history.row_count().unwrap(), 3);
|
||||
assert_eq!(
|
||||
history.first_row().unwrap(),
|
||||
Some(NOW - 30 * day + 3600),
|
||||
"the oldest row left"
|
||||
);
|
||||
assert_eq!(history.prune(NOW).unwrap(), 0, "nothing more to delete");
|
||||
assert!(
|
||||
fake.history.with_extension("db-wal").exists()
|
||||
@@ -525,3 +536,129 @@ fn a_server_that_will_not_start_is_reported_and_not_retried_for_a_minute() {
|
||||
assert_eq!(app.view(Range::Day).server.status, Status::Running);
|
||||
assert_eq!(app.view(Range::Day).server.error, None);
|
||||
}
|
||||
|
||||
/// The real output with `more` more Rust builds in it: that many more requests, misses and compiles.
|
||||
fn with_more_rust_builds(more: u64) -> String {
|
||||
let text = LIVE.replace(
|
||||
"\"compile_requests\":7351",
|
||||
&format!("\"compile_requests\":{}", 7351 + more),
|
||||
);
|
||||
let text = text.replace("\"Rust\":3256", &format!("\"Rust\":{}", 3256 + more));
|
||||
let text = text.replace("\"rust\":3256", &format!("\"rust\":{}", 3256 + more));
|
||||
let text = text.replace(
|
||||
"\"compilations\":3256",
|
||||
&format!("\"compilations\":{}", 3256 + more),
|
||||
);
|
||||
let text = text.replace(
|
||||
"\"cache_writes\":3256",
|
||||
&format!("\"cache_writes\":{}", 3256 + more),
|
||||
);
|
||||
text.replace(
|
||||
"\"compiler_write_duration\":{\"secs\":25343",
|
||||
&format!(
|
||||
"\"compiler_write_duration\":{{\"secs\":{}",
|
||||
25343 + 8 * more
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_bootstrap_is_not_redrawn_on_every_poll_of_a_build_in_flight() {
|
||||
let fake = Fake::new();
|
||||
let app = App::with_probe(fake.config(), fake.probe());
|
||||
let mut task = Task::memory();
|
||||
let rust_builds = |app: &App| {
|
||||
app.view(Range::Day)
|
||||
.build_times
|
||||
.first()
|
||||
.map_or(0, |t| t.compiles)
|
||||
};
|
||||
task.poll(&app, NOW);
|
||||
assert_eq!(rust_builds(&app), 0, "nothing seen yet");
|
||||
|
||||
// A build adds one Rust build between every pair of polls. Each is stored at once, but the
|
||||
// histogram (and with it the bootstrap) waits for the one-minute beat.
|
||||
for step in 1..6u64 {
|
||||
fake.answers(&with_more_rust_builds(step));
|
||||
task.poll(&app, NOW + (step as i64) * 10);
|
||||
assert_eq!(
|
||||
task.history.build_obs_stamp().unwrap().0,
|
||||
step as i64,
|
||||
"observation {step} is stored at once"
|
||||
);
|
||||
assert_eq!(
|
||||
rust_builds(&app),
|
||||
0,
|
||||
"but the bootstrap drawn at the first poll stands (step {step})"
|
||||
);
|
||||
}
|
||||
fake.answers(&with_more_rust_builds(6));
|
||||
task.poll(&app, NOW + 60);
|
||||
assert_eq!(
|
||||
rust_builds(&app),
|
||||
6,
|
||||
"a minute after the last draw, everything seen so far is drawn in"
|
||||
);
|
||||
|
||||
fake.answers(&with_more_rust_builds(7));
|
||||
task.poll(&app, NOW + 70);
|
||||
assert_eq!(
|
||||
rust_builds(&app),
|
||||
6,
|
||||
"and it stands again until the next beat"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_full_history_costs_few_rows_on_the_second_poll() {
|
||||
// Thirty days with a row every minute: the most there can ever be. Two languages miss most
|
||||
// minutes, so only one minute in ten gives a build observation.
|
||||
let fake = Fake::new();
|
||||
let app = App::with_probe(fake.config(), fake.probe());
|
||||
let mut task = Task::memory();
|
||||
let day = 86_400;
|
||||
let mut c = stats::Counters::default();
|
||||
let mut readings = Vec::new();
|
||||
for step in 0..43_200i64 {
|
||||
let (rust, cxx) = if step % 10 == 0 { (2, 0) } else { (1, 1) };
|
||||
c.totals.requests += 10;
|
||||
c.totals.executed += 8;
|
||||
c.totals.hits += 6;
|
||||
c.totals.misses += rust + cxx;
|
||||
c.totals.not_cacheable += 2;
|
||||
c.totals.cache_writes += rust + cxx;
|
||||
c.compilations += rust + cxx;
|
||||
c.ns = [
|
||||
c.ns[0] + 6 * 10_000_000,
|
||||
c.ns[1] + (rust + cxx) * 1_000_000_000,
|
||||
c.ns[2] + (rust + cxx) * 8_000_000_000,
|
||||
];
|
||||
c.langs = vec![
|
||||
("Assembler".to_owned(), [2, 0, 0]),
|
||||
("C/C++".to_owned(), [4, cxx, 0]),
|
||||
("Rust".to_owned(), [0, rust, 0]),
|
||||
];
|
||||
readings.push((NOW - 30 * day + step * 60, c.clone()));
|
||||
}
|
||||
task.history.fill(&readings).unwrap();
|
||||
assert_eq!(
|
||||
task.history.row_count().unwrap(),
|
||||
43_199,
|
||||
"the first reading is the baseline"
|
||||
);
|
||||
let observations = task.history.build_obs_stamp().unwrap().0;
|
||||
assert_eq!(observations, 4_319, "one for every tenth minute after the baseline");
|
||||
|
||||
task.poll(&app, NOW);
|
||||
let first = app.lock().views_rows;
|
||||
task.poll(&app, NOW + 10);
|
||||
let second = app.lock().views_rows;
|
||||
eprintln!("rows handed out: first poll {first} (reading {observations} build observations once), second poll {second}");
|
||||
assert!(
|
||||
first >= observations as usize,
|
||||
"the first poll reads every observation once"
|
||||
);
|
||||
assert!(second < 3_000, "the second poll handed out {second} rows");
|
||||
let v = app.view(Range::Day);
|
||||
assert_eq!(v.buckets.len(), 120);
|
||||
}
|
||||
Reference in new issue
Block a user