Skip to content

Commit

Permalink
pagebench: fixup after is_rel_block_key changes in #6266 (#6303)
Browse files Browse the repository at this point in the history
PR #6266 broke the getpage_latest_lsn benchmark.

Before this patch, we'd fail with

```
not implemented: split up range
```

because `r.start = rel size key` and `r.end = rel size key + 1`.

The filtering of the key ranges in that loop is a bit ugly, but,
I measured:
* setup with 180k layer files (20k tenants * 9 layers).
* total physical size is 463GiB
* 5k tenants, the range filtering takes `0.6 seconds` on an
i3en.3xlarge.
That's a tiny fraction of the overall time it takes for pagebench to get
ready to send requests. So, this is good enough for now / there are
other bottlenecks that are bigger.
  • Loading branch information
problame authored Jan 9, 2024
1 parent f94abba commit 4e1b0b8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
1 change: 1 addition & 0 deletions libs/pageserver_api/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ impl Key {
}
}

#[inline(always)]
pub fn is_rel_block_key(key: &Key) -> bool {
key.field1 == 0x00 && key.field4 != 0 && key.field6 != 0xffffffff
}
Expand Down
2 changes: 2 additions & 0 deletions libs/pageserver_api/src/keyspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ impl KeySpaceAccum {
}
}

#[inline(always)]
pub fn add_key(&mut self, key: Key) {
self.add_range(singleton_range(key))
}

#[inline(always)]
pub fn add_range(&mut self, range: Range<Key>) {
match self.accum.as_mut() {
Some(accum) => {
Expand Down
56 changes: 31 additions & 25 deletions pageserver/pagebench/src/cmd/getpage_latest_lsn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use futures::future::join_all;
use pageserver::pgdatadir_mapping::key_to_rel_block;
use pageserver::repository;
use pageserver_api::key::is_rel_block_key;
use pageserver_api::keyspace::KeySpaceAccum;
use pageserver_api::models::PagestreamGetPageRequest;

use utils::id::TenantTimelineId;
Expand Down Expand Up @@ -116,38 +117,42 @@ async fn main_impl(
.keyspace(timeline.tenant_id, timeline.timeline_id)
.await?;
let lsn = partitioning.at_lsn;

let ranges = partitioning
.keys
.ranges
.iter()
.filter_map(|r| {
let start = r.start;
let end = r.end;
// filter out non-relblock keys
match (is_rel_block_key(&start), is_rel_block_key(&end)) {
(true, true) => Some(KeyRange {
timeline,
timeline_lsn: lsn,
start: start.to_i128(),
end: end.to_i128(),
}),
(true, false) | (false, true) => {
unimplemented!("split up range")
}
(false, false) => None,
let start = Instant::now();
let mut filtered = KeySpaceAccum::new();
// let's hope this is inlined and vectorized...
// TODO: turn this loop into a is_rel_block_range() function.
for r in partitioning.keys.ranges.iter() {
let mut i = r.start;
while i != r.end {
if is_rel_block_key(&i) {
filtered.add_key(i);
}
})
.collect::<Vec<_>>();

anyhow::Ok(ranges)
i = i.next();
}
}
let filtered = filtered.to_keyspace();
let filter_duration = start.elapsed();

anyhow::Ok((
filter_duration,
filtered.ranges.into_iter().map(move |r| KeyRange {
timeline,
timeline_lsn: lsn,
start: r.start.to_i128(),
end: r.end.to_i128(),
}),
))
}
});
}
let mut total_filter_duration = Duration::from_secs(0);
let mut all_ranges: Vec<KeyRange> = Vec::new();
while let Some(res) = js.join_next().await {
all_ranges.extend(res.unwrap().unwrap());
let (filter_duration, range) = res.unwrap().unwrap();
all_ranges.extend(range);
total_filter_duration += filter_duration;
}
info!("filter duration: {}", total_filter_duration.as_secs_f64());

let live_stats = Arc::new(LiveStats::default());

Expand Down Expand Up @@ -256,6 +261,7 @@ async fn main_impl(
let r = &ranges[weights.sample(&mut rng)];
let key: i128 = rng.gen_range(r.start..r.end);
let key = repository::Key::from_i128(key);
assert!(is_rel_block_key(&key));
let (rel_tag, block_no) = key_to_rel_block(key)
.expect("we filter non-rel-block keys out above");
PagestreamGetPageRequest {
Expand Down

1 comment on commit 4e1b0b8

@github-actions
Copy link

@github-actions github-actions bot commented on 4e1b0b8 Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2306 tests run: 2217 passed, 0 failed, 89 skipped (full report)


Flaky tests (6)

Postgres 15

  • test_branch_and_gc: release
  • test_crafted_wal_end[last_wal_record_crossing_segment]: release
  • test_statvfs_pressure_min_avail_bytes: debug

Postgres 14

  • test_crafted_wal_end[wal_record_crossing_segment_followed_by_small_one]: debug
  • test_empty_branch_remote_storage_upload: debug
  • test_empty_tenant_size: debug

Code coverage (full report)

  • functions: 54.8% (10140 of 18511 functions)
  • lines: 81.6% (58076 of 71134 lines)

The comment gets automatically updated with the latest test results
4e1b0b8 at 2024-01-09T19:31:29.590Z :recycle:

Please sign in to comment.