Skip to content

Commit 373e47d

Browse files
authored
PagePool::{default -> new_for_test} + temporary hack for IN_MEMORY_CONFIG / test_index_scans (#2707)
1 parent d7d080d commit 373e47d

16 files changed

Lines changed: 70 additions & 71 deletions

File tree

crates/bench/benches/special.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn serialize_benchmarks<
141141
Arc::new(table_schema),
142142
spacetimedb_table::indexes::SquashedOffset::COMMITTED_STATE,
143143
);
144-
let pool = PagePool::default();
144+
let pool = PagePool::new_for_test();
145145
let mut blob_store = spacetimedb_table::blob_store::HashMapBlobStore::default();
146146

147147
let ptrs = data_pv

crates/core/src/db/datastore/locking_tx_datastore/datastore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ mod tests {
11571157
}
11581158

11591159
fn get_datastore() -> Result<Locking> {
1160-
Locking::bootstrap(Identity::ZERO, <_>::default())
1160+
Locking::bootstrap(Identity::ZERO, PagePool::new_for_test())
11611161
}
11621162

11631163
fn col(col: u16) -> ColList {

crates/core/src/db/relational_db.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ pub mod tests_utils {
16221622
history,
16231623
durability,
16241624
snapshot_repo,
1625-
PagePool::default(),
1625+
PagePool::new_for_test(),
16261626
)?;
16271627
assert_eq!(connected_clients.len(), expected_num_clients);
16281628
let db = db.with_row_count(Self::row_count_fn());
@@ -1828,7 +1828,7 @@ mod tests {
18281828
EmptyHistory::new(),
18291829
None,
18301830
None,
1831-
PagePool::default(),
1831+
PagePool::new_for_test(),
18321832
) {
18331833
Ok(_) => {
18341834
panic!("Allowed to open database twice")
@@ -2770,7 +2770,7 @@ mod tests {
27702770
Identity::ZERO,
27712771
Some(&repo),
27722772
Some(last_compress),
2773-
PagePool::default(),
2773+
PagePool::new_for_test(),
27742774
)?;
27752775

27762776
Ok(())
@@ -2795,7 +2795,8 @@ mod tests {
27952795
);
27962796

27972797
let last = repo.latest_snapshot()?;
2798-
let stdb = RelationalDB::restore_from_snapshot_or_bootstrap(identity, Some(&repo), last, PagePool::default())?;
2798+
let stdb =
2799+
RelationalDB::restore_from_snapshot_or_bootstrap(identity, Some(&repo), last, PagePool::new_for_test())?;
27992800

28002801
let out = TempDir::with_prefix("snapshot_test")?;
28012802
let dir = SnapshotsPath::from_path_unchecked(out.path());

crates/core/src/host/host_controller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ pub async fn extract_schema(program_bytes: Box<[u8]>, host_type: HostType) -> an
972972
};
973973

974974
let runtimes = HostRuntimes::new(None);
975-
let page_pool = PagePool::default();
975+
let page_pool = PagePool::new(None);
976976
let module_info = Host::try_init_in_memory_to_check(&runtimes, page_pool, database, program).await?;
977977
let module_info = Arc::into_inner(module_info).unwrap();
978978

crates/snapshot/tests/remote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async fn can_sync_a_snapshot() -> anyhow::Result<()> {
6060
assert_eq!(stats.objects_written, total_objects);
6161

6262
// Assert that the copied snapshot is valid.
63-
let pool = PagePool::default();
63+
let pool = PagePool::new_for_test();
6464
let dst_snapshot_full = dst_repo.read_snapshot(src.offset, &pool)?;
6565
Locking::restore_from_snapshot(dst_snapshot_full, pool)?;
6666

crates/table/benches/page_manager.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ fn reserve_empty_page(c: &mut Criterion) {
181181
let mut group = c.benchmark_group("reserve_empty_page");
182182
group.throughput(Throughput::Bytes(PAGE_DATA_SIZE as _));
183183
group.bench_function("leave_uninit", |b| {
184-
let pool = PagePool::default();
184+
let pool = PagePool::new_for_test();
185185
let mut pages = Pages::default();
186186
b.iter(|| {
187187
let _ = black_box(pages.reserve_empty_page(&pool, RESERVE_SIZE));
188188
});
189189
});
190190

191191
let fill_with_zeros = |_, _, pages: &mut Pages| {
192-
let pool = PagePool::default();
192+
let pool = PagePool::new_for_test();
193193
let page = pages.reserve_empty_page(&pool, RESERVE_SIZE).unwrap();
194194
let page = pages.get_page_mut(page);
195195
unsafe { page.zero_data() };
@@ -222,7 +222,7 @@ fn insert_one_page_fixed_len(c: &mut Criterion) {
222222
rows_per_page::<R>() as u64 * mem::size_of::<R>() as u64,
223223
));
224224
group.bench_function(name, |b| {
225-
let pool = PagePool::default();
225+
let pool = PagePool::new_for_test();
226226
let mut pages = Pages::default();
227227
// `0xa5` is the alternating bit pattern, which makes incorrect accesses obvious.
228228
insert_one_page_worth_fixed_len(&pool, &mut pages, visitor, &R::from_u64(0xa5a5a5a5_a5a5a5a5));
@@ -283,7 +283,7 @@ fn delete_one_page_fixed_len(c: &mut Criterion) {
283283
};
284284
iter_time_with(
285285
b,
286-
&mut (Pages::default(), PagePool::default()),
286+
&mut (Pages::default(), PagePool::new_for_test()),
287287
pre,
288288
|ptrs, _, (pages, _)| {
289289
for ptr in ptrs {
@@ -315,7 +315,7 @@ fn retrieve_one_page_fixed_len(c: &mut Criterion) {
315315
group.throughput(Throughput::Bytes(rows_per_page as u64 * mem::size_of::<R>() as u64));
316316

317317
group.bench_function(name, |b| {
318-
let pool = PagePool::default();
318+
let pool = PagePool::new_for_test();
319319
let mut pages = Pages::default();
320320

321321
let ptrs = fill_page_with_fixed_len_collect_row_pointers(
@@ -367,7 +367,7 @@ fn insert_with_holes_fixed_len(c: &mut Criterion) {
367367
group.throughput(Throughput::Bytes(num_to_delete_in_bytes as u64));
368368

369369
group.bench_function(delete_ratio.to_string(), |b| {
370-
let pool = PagePool::default();
370+
let pool = PagePool::new_for_test();
371371
let mut pages = Pages::default();
372372

373373
let mut rng = StdRng::seed_from_u64(0xa5a5a5a5_a5a5a5a5);
@@ -437,7 +437,7 @@ fn copy_filter_fixed_len(c: &mut Criterion) {
437437
let val = R::from_u64(0xdeadbeef_0badbeef);
438438
for keep_ratio in [0.1, 0.25, 0.5, 0.75, 0.9, 1.0] {
439439
let visitor = &NullVarLenVisitor;
440-
let pool = PagePool::default();
440+
let pool = PagePool::new_for_test();
441441
let mut pages = Pages::default();
442442

443443
let num_pages = 16;
@@ -537,7 +537,7 @@ fn table_insert_one_row(c: &mut Criterion) {
537537
let val = black_box(val.to_product());
538538

539539
// Insert before benching to alloc and fault in a page.
540-
let pool = PagePool::default();
540+
let pool = PagePool::new_for_test();
541541
let mut ctx = (table, NullBlobStore);
542542
let ptr = ctx.0.insert(&pool, &mut ctx.1, &val).unwrap().1.pointer();
543543
let pre = |_, (table, bs): &mut (Table, NullBlobStore)| {
@@ -588,7 +588,7 @@ fn table_delete_one_row(c: &mut Criterion) {
588588
let val = val.to_product();
589589

590590
// Insert before benching to alloc and fault in a page.
591-
let mut ctx = (table, NullBlobStore, PagePool::default());
591+
let mut ctx = (table, NullBlobStore, PagePool::new_for_test());
592592
let insert = |_: u64, (table, bs, pool): &mut (Table, NullBlobStore, PagePool)| {
593593
table.insert(pool, bs, &val).unwrap().1.pointer()
594594
};
@@ -637,7 +637,7 @@ fn table_extract_one_row(c: &mut Criterion) {
637637
let mut table = make_table_for_row_type::<R>(name);
638638
let val = val.to_product();
639639

640-
let pool = PagePool::default();
640+
let pool = PagePool::new_for_test();
641641
let mut blob_store = NullBlobStore;
642642
let row = black_box(table.insert(&pool, &mut blob_store, &val).unwrap().1);
643643
group.bench_function(name, |b| {
@@ -848,7 +848,7 @@ fn index_insert(c: &mut Criterion) {
848848
same_ratio: f64,
849849
) {
850850
let make_row_move = &mut make_row;
851-
let pool = PagePool::default();
851+
let pool = PagePool::new_for_test();
852852
let (tbl, index_id, num_same, _) =
853853
make_table_with_same_ratio::<R>(&pool, make_row_move, num_rows, same_ratio, false);
854854
let mut ctx = (tbl, NullBlobStore, pool);
@@ -905,7 +905,7 @@ fn index_seek(c: &mut Criterion) {
905905
) {
906906
let make_row_move = &mut make_row;
907907
let (tbl, index_id, num_same, num_diff) =
908-
make_table_with_same_ratio::<R>(&PagePool::default(), make_row_move, num_rows, same_ratio, unique);
908+
make_table_with_same_ratio::<R>(&PagePool::new_for_test(), make_row_move, num_rows, same_ratio, unique);
909909

910910
group.bench_with_input(
911911
bench_id_for_index(name, num_rows, same_ratio, num_same, unique),
@@ -972,7 +972,7 @@ fn index_delete(c: &mut Criterion) {
972972
same_ratio: f64,
973973
) {
974974
let make_row_move = &mut make_row;
975-
let pool = PagePool::default();
975+
let pool = PagePool::new_for_test();
976976
let (mut tbl, index_id, num_same, _) =
977977
make_table_with_same_ratio::<R>(&pool, make_row_move, num_rows, same_ratio, false);
978978

crates/table/src/eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ mod test {
241241
AlgebraicType::product([AlgebraicType::U8, AlgebraicType::U32]), // xpppxxxx
242242
])]);
243243

244-
let pool = PagePool::default();
244+
let pool = PagePool::new_for_test();
245245
let bs = &mut NullBlobStore;
246246
let mut table_a = crate::table::test::table(ty.clone());
247247
let mut table_b = crate::table::test::table(ty);

crates/table/src/eq_to_pv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ mod tests {
237237
// Turn `val` into a `RowRef`.
238238
let mut table = crate::table::test::table(ty);
239239
let blob_store = &mut HashMapBlobStore::default();
240-
let (_, row) = table.insert(&PagePool::default(), blob_store, &val).unwrap();
240+
let (_, row) = table.insert(&PagePool::new_for_test(), blob_store, &val).unwrap();
241241

242242
// Check eq algo.
243243
prop_assert_eq!(row, val);

crates/table/src/page.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2493,7 +2493,7 @@ pub(crate) mod tests {
24932493

24942494
#[test]
24952495
fn serde_round_trip_whole_page() {
2496-
let pool = PagePool::default();
2496+
let pool = PagePool::new_for_test();
24972497
let mut page = Page::new(u64_row_size());
24982498

24992499
// Construct an empty page, ser/de it, and assert that it's still empty.

crates/table/src/page_pool.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,26 @@ impl MemoryUsage for PagePool {
2222
}
2323
}
2424

25-
/// The default page pool has a size of 8 GiB.
26-
impl Default for PagePool {
27-
fn default() -> Self {
28-
Self::new(None)
25+
impl PagePool {
26+
pub fn new_for_test() -> Self {
27+
Self::new(Some(100 * size_of::<Page>()))
2928
}
30-
}
3129

32-
impl PagePool {
3330
/// Returns a new page pool with `max_size` bytes rounded down to the nearest multiple of 64 KiB.
3431
///
35-
/// if no size is provided, a default of 8 GiB is used.
32+
/// if no size is provided, a default of 1 page is used.
3633
pub fn new(max_size: Option<usize>) -> Self {
37-
const DEFAULT_MAX_SIZE: usize = 8 * (1 << 30); // 8 GiB
38-
const PAGE_SIZE: usize = 64 * (1 << 10); // 64 KiB, `size_of::<Page>()`
34+
const PAGE_SIZE: usize = size_of::<Page>();
35+
// TODO(centril): This effectively disables the page pool.
36+
// Currently, we have a test `test_index_scans`.
37+
// The test sets up a `Location` table, like in BitCraft, with a `chunk` field,
38+
// and populates it with 1000 different chunks with 1200 rows each.
39+
// Then it asserts that the cold latency of an index scan on `chunk` takes < 1 ms.
40+
// However, for reasons currently unknown to us,
41+
// a large page pool, with capacity `1 << 26` bytes, on i7-7700K, 64GB RAM,
42+
// will turn the latency into 30-40 ms.
43+
// As a precaution, we disable the page pool by default.
44+
const DEFAULT_MAX_SIZE: usize = PAGE_SIZE; // 1 page
3945

4046
let queue_size = max_size.unwrap_or(DEFAULT_MAX_SIZE) / PAGE_SIZE;
4147
let inner = Arc::new(PagePoolInner::new(queue_size));
@@ -163,18 +169,6 @@ impl MemoryUsage for PagePoolInner {
163169
}
164170
}
165171

166-
impl Default for PagePoolInner {
167-
fn default() -> Self {
168-
const MAX_PAGE_MEM: usize = 8 * (1 << 30); // 8 GiB
169-
170-
// 2 ^ 17 pages at most.
171-
// Each slot in the pool is `(AtomicCell, Box<Page>)` which takes up 16 bytes.
172-
// The pool will therefore have a fixed cost of 2^20 bytes, i.e., 2 MiB.
173-
const MAX_POOLED_PAGES: usize = MAX_PAGE_MEM / size_of::<Page>();
174-
Self::new(MAX_POOLED_PAGES)
175-
}
176-
}
177-
178172
#[inline]
179173
fn inc(atomic: &AtomicUsize) {
180174
atomic.fetch_add(1, Ordering::Relaxed);
@@ -246,7 +240,7 @@ mod tests {
246240

247241
#[test]
248242
fn page_pool_returns_same_page() {
249-
let pool = PagePool::default();
243+
let pool = PagePool::new_for_test();
250244
assert_metrics(&pool, 0, 0, 0, 0);
251245

252246
// Create a page and put it back.

0 commit comments

Comments
 (0)