-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pageserver: reorder upload queue when possible (#10218)
## Problem The upload queue currently sees significant head-of-line blocking. For example, index uploads act as upload barriers, and for every layer flush we schedule a layer and index upload, which effectively serializes layer uploads. Resolves #10096. ## Summary of changes Allow upload queue operations to bypass the queue if they don't conflict with preceding operations, increasing parallelism. NB: the upload queue currently schedules an explicit barrier after every layer flush as well (see #8550). This must be removed to enable parallelism. This will require a better mechanism for compaction backpressure, see e.g. #8390 or #5415.
- Loading branch information
1 parent
aa7323a
commit ffaa52f
Showing
8 changed files
with
1,029 additions
and
126 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//! Upload queue benchmarks. | ||
use std::str::FromStr as _; | ||
use std::sync::atomic::AtomicU32; | ||
use std::sync::Arc; | ||
|
||
use criterion::{criterion_group, criterion_main, Bencher, Criterion}; | ||
use pageserver::tenant::metadata::TimelineMetadata; | ||
use pageserver::tenant::remote_timeline_client::index::LayerFileMetadata; | ||
use pageserver::tenant::storage_layer::LayerName; | ||
use pageserver::tenant::upload_queue::{Delete, UploadOp, UploadQueue, UploadTask}; | ||
use pageserver::tenant::IndexPart; | ||
use pprof::criterion::{Output, PProfProfiler}; | ||
use utils::generation::Generation; | ||
use utils::shard::{ShardCount, ShardIndex, ShardNumber}; | ||
|
||
// Register benchmarks with Criterion. | ||
criterion_group!( | ||
name = benches; | ||
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); | ||
targets = bench_upload_queue_next_ready, | ||
); | ||
criterion_main!(benches); | ||
|
||
/// Benchmarks the cost of UploadQueue::next_ready() with the given number of in-progress tasks | ||
/// (which is equivalent to tasks ahead of it in the queue). This has linear cost, and the upload | ||
/// queue as a whole is thus quadratic. | ||
/// | ||
/// UploadOp::UploadLayer requires an entire tenant and timeline to construct, so we just test | ||
/// Delete and UploadMetadata instead. This is incidentally the most expensive case. | ||
fn bench_upload_queue_next_ready(c: &mut Criterion) { | ||
let mut g = c.benchmark_group("upload_queue_next_ready"); | ||
for inprogress in [0, 1, 10, 100, 1_000, 10_000, 100_000, 1_000_000] { | ||
g.bench_function(format!("inprogress={inprogress}"), |b| { | ||
run_bench(b, inprogress).unwrap() | ||
}); | ||
} | ||
|
||
fn run_bench(b: &mut Bencher, inprogress: usize) -> anyhow::Result<()> { | ||
// Construct two layers. layer0 is in the indexes, layer1 will be deleted. | ||
let layer0 = LayerName::from_str("000000000000000000000000000000000000-100000000000000000000000000000000000__00000000016B59D8-00000000016B5A51").expect("invalid name"); | ||
let layer1 = LayerName::from_str("100000000000000000000000000000000001-200000000000000000000000000000000000__00000000016B59D8-00000000016B5A51").expect("invalid name"); | ||
|
||
let metadata = LayerFileMetadata { | ||
shard: ShardIndex::new(ShardNumber(1), ShardCount(2)), | ||
generation: Generation::Valid(1), | ||
file_size: 0, | ||
}; | ||
|
||
// Construct the (initial and uploaded) index with layer0. | ||
let mut index = IndexPart::empty(TimelineMetadata::example()); | ||
index.layer_metadata.insert(layer0, metadata.clone()); | ||
|
||
// Construct the queue. | ||
let mut queue = UploadQueue::Uninitialized; | ||
let queue = queue.initialize_with_current_remote_index_part(&index)?; | ||
|
||
// Populate inprogress_tasks with a bunch of layer1 deletions. | ||
let delete = UploadOp::Delete(Delete { | ||
layers: vec![(layer1, metadata)], | ||
}); | ||
|
||
for task_id in 0..(inprogress as u64) { | ||
queue.inprogress_tasks.insert( | ||
task_id, | ||
Arc::new(UploadTask { | ||
task_id, | ||
retries: AtomicU32::new(0), | ||
op: delete.clone(), | ||
}), | ||
); | ||
} | ||
|
||
// Benchmark index upload scheduling. | ||
let index_upload = UploadOp::UploadMetadata { | ||
uploaded: Box::new(index), | ||
}; | ||
|
||
b.iter(|| { | ||
queue.queued_operations.push_front(index_upload.clone()); | ||
assert!(queue.next_ready().is_some()); | ||
}); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
ffaa52f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7455 tests run: 7072 passed, 1 failed, 382 skipped (full report)
Failures on Postgres 16
test_layer_map[github-actions-selfhosted]
: release-x86-64Flaky tests (3)
Postgres 17
test_nbtree_pagesplit_cycleid
: release-arm64test_timeline_ancestor_detach_idempotent_success[shards_initial_after2]
: release-x86-64Postgres 15
test_scrubber_physical_gc_ancestors[None]
: release-arm64Code coverage* (full report)
functions
:32.9% (8136 of 24765 functions)
lines
:48.1% (68165 of 141834 lines)
* collected from Rust tests only
ffaa52f at 2025-01-14T18:52:05.556Z :recycle: