Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions apps/origin-src/benches/packs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Packs: writing and reading a million statements loose and packed,
//! compacting them, and looking objects up across several packs. Run on a
//! real disk: syncs cost nothing on a RAM-backed file system.
//! Benchmarks for packs: writing and reading a million statements loose and
//! packed, compacting them, and finding objects across several packs. Run
//! on a real disk: syncs cost nothing on a RAM-backed file system.

use std::path::PathBuf;
use std::sync::{LazyLock, OnceLock};
Expand All @@ -25,7 +25,8 @@ static ROOT: OnceLock<PathBuf> = OnceLock::new();
/// How many statements the large stores hold.
const STATEMENTS: usize = 1_000_000;

/// `count` distinct statements, like a CI runner issues, from `seed` on.
/// Returns `count` distinct statements, like those a CI runner issues,
/// numbered from `seed`.
fn statements(seed: usize, count: usize) -> Vec<EncodedObject> {
(seed..seed + count)
.map(|seed| {
Expand Down Expand Up @@ -57,17 +58,16 @@ fn store() -> Fixture {
(dir, store)
}

/// A store of the million statements, loose.
/// A store holding the million statements as loose objects.
fn loose() -> Fixture {
let (dir, store) = store();
store.write_all(&STATEMENTS_1M).unwrap();
(dir, store)
}

/// A store of the million statements in `packs` packs, halving in size so
/// compaction keeps them apart. The first pack takes the remainder: each
/// later one is then at most half the one before, which compaction never
/// merges into it.
/// A store holding the million statements in `packs` packs. Each pack after
/// the first is at most half the size of the one before, so compaction never
/// merges them. The first pack takes the remainder.
fn packed(packs: u32) -> Fixture {
let (dir, store) = store();
let later: usize = (1..packs).map(|pack| STATEMENTS >> (pack + 1)).sum();
Expand Down Expand Up @@ -103,7 +103,7 @@ static PACKED: [LazyLock<Fixture, fn() -> Fixture>; 3] = [
LazyLock::new(|| packed(16)),
];

/// The large packed store with `packs` packs.
/// The packed store with `packs` packs: 1, 4 or 16.
fn packed_store(packs: u32) -> &'static Store {
let index = match packs {
1 => 0,
Expand All @@ -125,8 +125,7 @@ fn write_loose(bencher: Bencher<'_, '_>) {
.bench_local_refs(|(_, store)| store.write_all(&STATEMENTS_1M).unwrap());
}

/// Compacting a million loose statements into one pack: what packing costs
/// on top of writing them loose.
/// Compacting a million loose statements into one pack.
#[divan::bench(sample_count = 3, sample_size = 1)]
fn compact(bencher: Bencher<'_, '_>) {
bencher
Expand All @@ -135,8 +134,8 @@ fn compact(bencher: Bencher<'_, '_>) {
.bench_local_refs(|(_, store)| store.compact().unwrap());
}

/// Reading back every statement of a million, in id order, from one
/// thread.
/// Reading every statement of a million back, in id order, from one thread,
/// loose or packed.
#[divan::bench(args = ["loose", "packed"], sample_count = 3, sample_size = 1)]
fn read_all(bencher: Bencher<'_, '_>, layout: &str) {
let store = match layout {
Expand All @@ -152,7 +151,7 @@ fn read_all(bencher: Bencher<'_, '_>, layout: &str) {
});
}

/// Reading one statement of a million, loose or in the smallest of
/// Reading one statement of a million, loose or from the smallest of
/// `packs` packs, which is searched last.
#[divan::bench(args = [0, 1, 4, 16])]
fn read_one(bencher: Bencher<'_, '_>, packs: u32) {
Expand All @@ -167,8 +166,8 @@ fn read_one(bencher: Bencher<'_, '_>, packs: u32) {
}

/// Looking up an object the store doesn't have, among a million statements
/// loose or in `packs` packs: every pack is searched and the manifest
/// reread.
/// loose or in `packs` packs. Every pack is searched and the manifest is
/// read again.
#[divan::bench(args = [0, 1, 4, 16])]
fn contains_absent(bencher: Bencher<'_, '_>, packs: u32) {
let store = if packs == 0 {
Expand Down
5 changes: 3 additions & 2 deletions apps/origin-src/benches/snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Snapshotting a working copy: the cost behind every command that reads it.
//! Objects are written durably, as the commands write them.
//! Benchmarks for snapshotting a working copy, which every command that
//! reads the working copy does. Objects are written durably, as the commands
//! write them.

use std::sync::atomic::{AtomicU64, Ordering};

Expand Down
44 changes: 23 additions & 21 deletions apps/origin-src/benches/store.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Store throughput: durable writes with and without batching, verified
//! reads, target appends, and the record index. Run on a real disk: syncs
//! cost nothing on a RAM-backed file system.
//! Benchmarks for the store: durable writes with and without batching,
//! verified reads, target appends, and the record index. Run on a real disk:
//! syncs cost nothing on a RAM-backed file system.

use std::fs::File;
use std::io;
Expand All @@ -23,7 +23,8 @@ fn main() {
divan::main();
}

/// Source-code-like content, which compresses like real files do.
/// Returns `len` bytes of source-code-like content, distinct for each
/// `seed`, which compresses like real files do.
fn content(len: usize, seed: usize) -> Vec<u8> {
format!("fn item_{seed}() -> usize {{ {seed} }}\n")
.into_bytes()
Expand All @@ -46,8 +47,8 @@ fn store_on<P: Platform>(platform: P) -> (tempfile::TempDir, Store<P>) {
(dir, store)
}

/// Writing new objects one batch each: a file and a directory sync per
/// object.
/// Writing new objects one batch each, which costs a file sync and a
/// directory sync per object.
#[divan::bench(args = [4 * 1024, 1024 * 1024], sample_count = 20)]
fn write_unbatched(bencher: Bencher<'_, '_>, len: usize) {
let (_dir, store) = store();
Expand All @@ -61,8 +62,8 @@ fn write_unbatched(bencher: Bencher<'_, '_>, len: usize) {
.bench_local_refs(|object| store.write_all(slice::from_ref(object)).unwrap());
}

/// Writing new 4 KiB objects in one batch, staged from every core: the
/// first snapshot of a tree of that many files.
/// Writing `count` new 4 KiB objects in one batch, staged from every core,
/// like the first snapshot of a tree of that many files.
#[divan::bench(args = [1_000, 20_000], sample_count = 5, sample_size = 1)]
fn write_batch(bencher: Bencher<'_, '_>, count: usize) {
let objects: Vec<_> = (0..count)
Expand All @@ -75,7 +76,7 @@ fn write_batch(bencher: Bencher<'_, '_>, count: usize) {
}

/// Walking a store of 20k objects for the temporary files crashed writes
/// left: what garbage collection pays.
/// left behind, as garbage collection does.
#[divan::bench(sample_count = 20)]
fn remove_stale_temps(bencher: Bencher<'_, '_>) {
let (_dir, store) = store();
Expand All @@ -86,9 +87,9 @@ fn remove_stale_temps(bencher: Bencher<'_, '_>) {
bencher.bench(|| store.remove_stale_temps().unwrap());
}

/// Writing objects the store already has: the common case when
/// snapshotting. The batch syncs the directory of each, for the writer that
/// renamed it there may not have yet.
/// Writing objects the store already has, the common case when
/// snapshotting. The batch still syncs each object's directory, since the
/// writer that put the object there may not have synced it yet.
#[divan::bench(args = [1, 1_000, 20_000])]
fn write_existing(bencher: Bencher<'_, '_>, count: usize) {
let (_dir, store) = store();
Expand All @@ -101,7 +102,7 @@ fn write_existing(bencher: Bencher<'_, '_>, count: usize) {
.bench(|| store.write_all(black_box(&objects)).unwrap());
}

/// Reading, decompressing, and verifying objects: the cost of checkouts.
/// Reading, decompressing and verifying an object, as checkouts do.
#[divan::bench(args = [4 * 1024, 1024 * 1024])]
fn read(bencher: Bencher<'_, '_>, len: usize) {
let (_dir, store) = store();
Expand All @@ -112,7 +113,7 @@ fn read(bencher: Bencher<'_, '_>, len: usize) {
.bench(|| store.read(black_box(object.id())).unwrap());
}

/// Appending an acceptance to a target: the durable part of every landing.
/// Appending an acceptance to a target, the durable step of every landing.
#[divan::bench(sample_count = 20)]
fn append(bencher: Bencher<'_, '_>) {
let (_dir, store) = store();
Expand All @@ -135,9 +136,10 @@ fn append(bencher: Bencher<'_, '_>) {
});
}

/// `count` records, as a busy repository receives them: a revision of one
/// of a hundred changes, evolving from that change's previous one, then nine
/// statements about it.
/// Returns `count` records like a busy repository receives them: every
/// tenth is a revision of one of a hundred changes, in turn, evolving from
/// that change's previous revision, and the nine after it are statements
/// about it.
fn records(count: usize) -> Vec<EncodedObject> {
let snapshot = TreeId::from(Tree::default().encode().id());
let mut heads = vec![None; 100];
Expand Down Expand Up @@ -176,7 +178,7 @@ fn records(count: usize) -> Vec<EncodedObject> {
.collect()
}

/// The native platform without syncs, to measure what syncs hide.
/// The native platform with every sync skipped, to measure what syncs cost.
#[derive(Clone, Copy, Debug, Default)]
struct NoSync;

Expand Down Expand Up @@ -211,9 +213,9 @@ impl FileSystem for NoSync {
}

/// Writing new records in one batch, which indexes them, against blobs of
/// the same content, which aren't indexed: the difference is what indexing
/// costs, which [`NoSync`] shows apart from the syncs. One record is what
/// issuing a statement costs.
/// the same bytes, which aren't indexed. The difference is what indexing
/// costs; [`NoSync`] shows it without the syncs. A batch of one, a
/// revision, is the cost of writing a single record.
#[divan::bench(
types = [Native, NoSync],
consts = [true, false],
Expand Down
Loading
Loading