8000 bench: cover memory-limit controls and schedule v3 acceptance (Refs #776 P15) by adityamukho · Pull Request #831 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
8 changes: 8 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ jobs:
filter: "^query/"
file: bench_query.txt

# P15 / G07: four enforcement on/off controls, 10k committed facts.
# Accounting itself is always on. Reserve 2–5 job-minutes; timing
# evidence is deferred to the serial phase-B dispatch.
- name: memory_meter
filter: "^memory_meter/"
file: bench_memory_meter.txt
required_case: '"memory_meter"'

# P02: four existing execute cases plus eight preparation/cursor/slot
# cases. Reserve 4–10 job-minutes pending phase-B timing.
- name: prepared
Expand Down
177 changes: 103 additions & 74 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
@@ -1,104 +1,133 @@
name: Smoke Suite (nightly)

# Scheduled workflows come from main. Keep this file identical on main/v3.
# Main's original smoke runs at 05:00 UTC; v3 acceptance runs at 17:00 UTC.
run-name: >-
Smoke Suite (${{ github.event_name == 'workflow_dispatch' && inputs.ref
|| (github.event.schedule == '0 17 * * *' && 'v3' || 'main') }})

on:
schedule:
- cron: "0 5 * * *"
- cron: "0 17 * * *"
workflow_dispatch:
inputs:
ref:
description: Source ref to check (v3 acceptance skips when absent)
required: true
default: v3

permissions:
contents: read

jobs:
smoke:
name: Long-haul smoke suite
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- uses: actions/checkout@v4

- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable

- name: Run smoke suite
run: cargo test --test smoke_test -- --include-ignored --nocapture
env:
RUST_BACKTRACE: 1

- name: Size per fact at 1M facts (spec §11)
run: cargo test --lib size_per_fact_in_433_shape_1m -- --include-ignored --nocapture
env:
RUST_BACKTRACE: 1

# #548: a recursive rule deriving about 5M facts completes, and its peak
# RSS follows the derived relation.
recursive-acceptance:
name: Recursive rules at 5M derived facts
runs-on: ubuntu-latest
timeout-minutes: 45

steps:
- uses: actions/checkout@v4

- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable

- name: Run the acceptance test
run: cargo test --profile bench --test recursive_acceptance_test -- --ignored --nocapture
env:
RUST_BACKTRACE: 1
# Manual refs and the pinned v3 source run in the default-branch workflow's
# context. These cold-build jobs need no shared cache access.
cache-mode: none

# #549 / #575: 1M aggregate groups complete or stop with QRY-012 under a
# limit; a 13-pattern cartesian product streams in a few MiB.
memory-limit-acceptance:
name: Query memory limit acceptance
jobs:
source:
name: Pin source and inspect acceptance availability
runs-on: ubuntu-latest
timeout-minutes: 30

timeout-minutes: 5
outputs:
sha: ${{ steps.source.outputs.sha }}
acceptance: ${{ steps.source.outputs.acceptance }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || (github.event.schedule == '0 17 * * *' && 'v3' || 'main') }}
- name: Record actual checkout
id: source
run: |
sha=$(git rev-parse HEAD)
echo "sha=$sha" >> "$GITHUB_OUTPUT"
echo "Measured source: $sha; workflow: ${{ github.workflow_sha }}" >> "$GITHUB_STEP_SUMMARY"
acceptance=true
for test in recursive memory_limit limit large_transaction; do
if [ ! -f "tests/${test}_acceptance_test.rs" ]; then
acceptance=false
fi
done
echo "acceptance=$acceptance" >> "$GITHUB_OUTPUT"
echo "v3 acceptance available: $acceptance" >> "$GITHUB_STEP_SUMMARY"
# A scheduled v3 checkout must never silently skip its acceptance.
if [ '${{ github.event.schedule }}' = '0 17 * * *' ] && [ "$acceptance" != true ]; then
echo 'v3 acceptance targets missing' >&2
exit 1
fi

- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable

- name: Run the acceptance tests
run: cargo test --profile bench --test memory_limit_acceptance_test -- --ignored --nocapture --test-threads=1
env:
RUST_BACKTRACE: 1

# #306: `:limit 10` over 10M facts stops once it has its rows, in a
# 64 KiB query memory limit.
limit-acceptance:
name: Limit acceptance
smoke:
name: Long-haul smoke suite
needs: source
if: github.event.schedule != '0 17 * * *'
runs-on: ubuntu-latest
timeout-minutes: 30

timeout-minutes: 15
steps:
- uses: actions/checkout@v4

with:
# The original smoke suite always exercises trusted main. Only the
# isolated acceptance jobs below consume the selected source SHA.
ref: main
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable

- name: Run the acceptance test
run: cargo test --profile bench --test limit_acceptance_test -- --ignored --nocapture
- name: Run smoke suite
run: |
echo "Main smoke source: $(git rev-parse HEAD)" >> "$GITHUB_STEP_SUMMARY"
cargo test --test smoke_test -- --include-ignored --nocapture
env:
RUST_BACKTRACE: 1

# #550: a 1M-fact transact holds at most one chunk of facts and commits as
# a checkpoint; peak RSS is printed. test-hooks: the statement reader's
# high-water mark.
large-transaction-acceptance:
name: Large transaction acceptance
# Separate from Bencher latency: these existing tests assert fixed retained
# state/RSS bounds (and QRY-012 exhaustion), rather than uploading RSS as time.
# Runtime within the existing 15/30/45-minute budgets remains unverified.
acceptance:
name: v3 acceptance / ${{ matrix.name }}
needs: source
if: needs.source.outputs.acceptance == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30

timeout-minutes: ${{ matrix.timeout }}
strategy:
fail-fast: false
matrix:
include:
- name: recursive
timeout: 45
command: cargo test --profile bench --test recursive_acceptance_test -- --ignored --nocapture
- name: memory-limit
timeout: 30
command: cargo test --profile bench --test memory_limit_acceptance_test -- --ignored --nocapture --test-threads=1
- name: limit
timeout: 30
command: cargo test --profile bench --test limit_acceptance_test -- --ignored --nocapture
- name: large-transaction
timeout: 30
command: cargo test --profile bench --features test-hooks --test large_transaction_acceptance_test -- --ignored --nocapture
- name: size-per-fact
timeout: 15
command: cargo test --lib size_per_fact_in_433_shape_1m -- --include-ignored --nocapture
steps:
- uses: actions/checkout@v4

with:
ref: ${{ needs.source.outputs.sha }}
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable

- name: Run the acceptance test
run: cargo test --profile bench --features test-hooks --test large_transaction_acceptance_test -- --ignored --nocapture
- name: Run acceptance and retain source/test evidence
env:
RUST_BACKTRACE: 1
ACCEPTANCE_COMMAND: ${{ matrix.command }}
run: |
set -o pipefail
{
echo "Source: $(git rev-parse HEAD)"
echo "Workflow: ${{ github.workflow_sha }}"
echo "Command: $ACCEPTANCE_COMMAND"
$ACCEPTANCE_COMMAND
} 2>&1 | tee acceptance.txt
- name: Retain acceptance output including executed test names and RSS/state
if: always()
uses: actions/upload-artifact@v6
with:
name: acceptance-${{ matrix.name }}
path: acceptance.txt
if-no-files-found: error
retention-days: 30
3 changes: 3 additions & 0 deletions benches/minigraf_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ mod helpers;
mod history;
#[path = "minigraf_bench/keyword_equality.rs"]
mod keyword_equality;
#[path = "minigraf_bench/memory_meter.rs"]
mod memory_meter;
#[path = "minigraf_bench/pagination.rs"]
mod pagination;

Expand Down Expand Up @@ -2111,6 +2113,7 @@ criterion_group!(
set_storage::bench_set_storage,
chunked_transactions::bench_chunked_transactions,
bench_query,
memory_meter::bench_memory_meter,
distinct::bench_distinct,
pagination::bench_pagination,
operator_paths::bench_operator_paths,
Expand Down
79 changes: 79 additions & 0 deletions benches/minigraf_bench/memory_meter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//! #776 P15 / G07: finite memory-limit enforcement versus unlimited queries.
//!
//! Accounting is always enabled in the engine: `usize::MAX` disables the
//! limit, not charges. These pairs measure enforcement on/off, not the cost
//! of accounting versus an unmetered engine. The separate smoke acceptance
//! jobs enforce state/RSS bounds; Criterion reports latency only.

use criterion::{BenchmarkId, Criterion};
use minigraf::{Minigraf, OpenOptions, Value};
use std::hint::black_box;
use std::time::Duration;

fn drain(db: &Minigraf, query: &str) -> (usize, i64) {
let mut cursor = db.query(query).unwrap();
let mut rows = 0;
let mut total = 0;
while let Some(batch) = cursor.next_batch(256).unwrap() {
rows += batch.len();
for row in batch.rows() {
let Some(Value::Integer(n)) = row.last() else {
panic!("expected integer count");
};
total += n;
}
black_box(batch);
}
(rows, total)
}

pub fn bench_memory_meter(c: &mut Criterion) {
let mut group = c.benchmark_group("memory_meter");
group.sample_size(10);
group.warm_up_time(Duration::from_secs(1));
group.measurement_time(Duration::from_secs(3));

for (shape, query, expected_rows) in [
("count", "(query [:find (count ?v) :where [?e :val ?v]])", 1),
(
"hash_groups",
// An expression-bound key cannot use the committed input-order
// proof. All 10k groups stay in Aggregate until input is drained.
"(query [:find ?g (count ?e) :where [?e :val ?v] [(+ ?v 0) ?g]])",
10_000,
),
] {
for (mode, limit) in [("unlimited", usize::MAX), ("limited", 8 << 20)] {
group.bench_function(BenchmarkId::new(shape, format!("{mode}/10k")), |b| {
// Setup is lazy and untimed, including file copy, open, cache
// warm-up, validation and a low-limit rejection control.
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("meter.graph");
super::helpers::populate_file(10_000, path.to_str().unwrap());
let db = OpenOptions::new()
.query_memory_limit(limit)
.read_only(true)
.path(&path)
.open()
.unwrap();
assert_eq!(drain(&db, query), (expected_rows, 10_000));
if shape == "hash_groups" {
let constrained = OpenOptions::new()
.query_memory_limit(4 << 10)
.read_only(true)
.path(&path)
.open()
.unwrap();
let err = constrained.execute(query).err().expect("limit enforced");
assert_eq!(err.code(), "QRY-012");
assert!(
err.to_string().contains("Aggregate"),
"hash aggregate state"
);
}
b.iter(|| black_box(drain(&db, black_box(query))));
});
}
}
group.finish();
}
Loading
0