Skip to content

Commit a776344

Browse files
authored
persist: count compaction fast-path eligible reqs (#18380)
1 parent e3b797f commit a776344

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/persist-client/src/internal/compact.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use mz_ore::task::spawn;
2424
use mz_persist::location::Blob;
2525
use mz_persist_types::codec_impls::VecU8Schema;
2626
use mz_persist_types::{Codec, Codec64};
27-
use timely::progress::Timestamp;
27+
use timely::progress::{Antichain, Timestamp};
2828
use timely::PartialOrder;
2929
use tokio::sync::mpsc::Sender;
3030
use tokio::sync::{mpsc, oneshot, TryAcquireError};
@@ -410,6 +410,31 @@ where
410410
schemas: Schemas<K, V>,
411411
) -> Result<CompactRes<T>, anyhow::Error> {
412412
let () = Self::validate_req(&req)?;
413+
414+
// We introduced a fast-path optimization in https://github.com/MaterializeInc/materialize/pull/15363
415+
// but had to revert it due to a very scary bug. Here we count how many of our compaction reqs
416+
// could be eligible for the optimization to better understand whether it's worth trying to
417+
// reintroduce it.
418+
let mut single_nonempty_batch = None;
419+
for batch in &req.inputs {
420+
if batch.len > 0 {
421+
match single_nonempty_batch {
422+
None => single_nonempty_batch = Some(batch),
423+
Some(_previous_nonempty_batch) => {
424+
single_nonempty_batch = None;
425+
break;
426+
}
427+
}
428+
}
429+
}
430+
if let Some(single_nonempty_batch) = single_nonempty_batch {
431+
if single_nonempty_batch.runs.len() == 0
432+
&& single_nonempty_batch.desc.since() != &Antichain::from_elem(T::minimum())
433+
{
434+
metrics.compaction.fast_path_eligible.inc();
435+
}
436+
}
437+
413438
// compaction needs memory enough for at least 2 runs and 2 in-progress parts
414439
assert!(cfg.compaction_memory_bound_bytes >= 4 * cfg.batch.blob_target_size);
415440
// reserve space for the in-progress part to be held in-mem representation and columnar

src/persist-client/src/internal/metrics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ pub struct CompactionMetrics {
660660
pub(crate) not_all_prefetched: IntCounter,
661661
pub(crate) parts_prefetched: IntCounter,
662662
pub(crate) parts_waited: IntCounter,
663+
pub(crate) fast_path_eligible: IntCounter,
663664

664665
pub(crate) applied_exact_match: IntCounter,
665666
pub(crate) applied_subset_match: IntCounter,
@@ -748,6 +749,10 @@ impl CompactionMetrics {
748749
name: "mz_persist_compaction_parts_waited",
749750
help: "count of compaction parts that had to be waited on",
750751
)),
752+
fast_path_eligible: registry.register(metric!(
753+
name: "mz_persist_compaction_fast_path_eligible",
754+
help: "count of compaction requests that could have used the fast-path optimization",
755+
)),
751756
applied_exact_match: registry.register(metric!(
752757
name: "mz_persist_compaction_applied_exact_match",
753758
help: "count of merge results that exactly replaced a SpineBatch",

0 commit comments

Comments
 (0)