Skip to content

Commit e99c5cd

Browse files
konardclaude
andcommitted
Make benchmark parameters configurable via environment variables
- Remove unused import: doublets::Doublets in lib.rs - Replace hardcoded BACKGROUND_LINKS constant with background_links() function - Add benchmark_links() function for configurable operation count - Update all benchmark files to use the new functions - Rename BENCHMARK_LINK_COUNT to BENCHMARK_LINKS in workflow - Add BENCHMARK_BACKGROUND_LINKS (100 for PRs, 100000 for main branch) Environment variables: - BENCHMARK_LINKS: number of links per operation (10 for PRs, 1000 for main) - BENCHMARK_BACKGROUND_LINKS: background links count (100 for PRs, 100000 for main) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent e2eeed2 commit e99c5cd

File tree

9 files changed

+49
-45
lines changed

9 files changed

+49
-45
lines changed

.github/workflows/rust.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ jobs:
6767
POSTGRES_PASSWORD: postgres
6868
POSTGRES_DB: postgres
6969
# Use 1000 links for main/master branch benchmarks, 10 for pull requests
70-
BENCHMARK_LINK_COUNT: ${{ (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) && '1000' || '10' }}
70+
BENCHMARK_LINKS: ${{ (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) && '1000' || '10' }}
71+
# Use 100000 background links for main/master branch, 100 for pull requests
72+
BENCHMARK_BACKGROUND_LINKS: ${{ (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) && '100000' || '100' }}
7173
run: |
7274
set -o pipefail
7375
cargo bench --bench bench -- --output-format bencher | tee out.txt

rust/benches/benchmarks/create.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use {
88
parts::LinkPart,
99
split::{self, DataPart, IndexPart}, unit,
1010
},
11-
linkspsql::{bench, Benched, Client, connect, Exclusive, Fork, Transaction},
11+
linkspsql::{bench, benchmark_links, Benched, Client, connect, Exclusive, Fork, Transaction},
1212
std::{alloc::Global, time::{Duration, Instant}},
1313
};
1414

@@ -17,9 +17,10 @@ fn bench<T: LinkType, B: Benched + Doublets<T>>(
1717
id: &str,
1818
mut benched: B,
1919
) {
20+
let links = benchmark_links();
2021
group.bench_function(id, |bencher| {
2122
bench!(|fork| as B {
22-
for _ in 0..1_000 {
23+
for _ in 0..links {
2324
let _ = elapsed! {fork.create_point()?};
2425
}
2526
})(bencher, &mut benched);

rust/benches/benchmarks/delete.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@ use {
77
parts::LinkPart,
88
split::{self, DataPart, IndexPart}, unit,
99
},
10-
linkspsql::{bench, Benched, Client, connect, Exclusive, Fork, Transaction, BACKGROUND_LINKS},
10+
linkspsql::{bench, background_links, benchmark_links, Benched, Client, connect, Exclusive, Fork, Transaction},
1111
std::{alloc::Global, time::{Duration, Instant}},
1212
};
1313
fn bench<B: Benched + Doublets<usize>>(
1414
group: &mut BenchmarkGroup<WallTime>,
1515
id: &str,
1616
mut benched: B,
1717
) {
18+
let bg_links = background_links();
19+
let links = benchmark_links();
1820
group.bench_function(id, |bencher| {
1921
bench!(|fork| as B {
20-
for _prepare in BACKGROUND_LINKS..BACKGROUND_LINKS + 1_000 {
22+
for _prepare in bg_links..bg_links + links {
2123
let _ = fork.create_point();
2224
}
23-
for id in (BACKGROUND_LINKS..=BACKGROUND_LINKS + 1_000).rev() {
25+
for id in (bg_links..=bg_links + links).rev() {
2426
let _ = elapsed! {fork.delete(id)?};
2527
}
2628
})(bencher, &mut benched);

rust/benches/benchmarks/each/concrete.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use {
88
split::{self, DataPart, IndexPart},
99
unit, Doublets,
1010
},
11-
linkspsql::{bench, connect, Benched, Client, Exclusive, Fork, Transaction},
11+
linkspsql::{background_links, bench, connect, Benched, Client, Exclusive, Fork, Transaction},
1212
std::{
1313
alloc::Global,
1414
time::{Duration, Instant},
@@ -21,15 +21,10 @@ fn bench<B: Benched + Doublets<usize>>(
2121
) {
2222
let handler = |_| Flow::Continue;
2323
let any = LinksConstants::new().any;
24+
let bg_links = background_links();
2425
group.bench_function(id, |bencher| {
2526
bench!(|fork| as B {
26-
for index in 1..=1_000 {
27-
elapsed! {fork.each_by([any, index, index], handler)};
28-
}
29-
for index in 1_001..=2_000 {
30-
elapsed! {fork.each_by([any, index, index], handler)};
31-
}
32-
for index in 2_001..=BACKGROUND_LINKS {
27+
for index in 1..=bg_links {
3328
elapsed! {fork.each_by([any, index, index], handler)};
3429
}
3530
})(bencher, &mut benched);

rust/benches/benchmarks/each/identity.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use {
88
split::{self, DataPart, IndexPart},
99
unit, Doublets,
1010
},
11-
linkspsql::{bench, connect, Benched, Client, Exclusive, Fork, Transaction},
11+
linkspsql::{background_links, bench, connect, Benched, Client, Exclusive, Fork, Transaction},
1212
std::{
1313
alloc::Global,
1414
time::{Duration, Instant},
@@ -22,15 +22,10 @@ fn bench<B: Benched + Doublets<usize>>(
2222
) {
2323
let handler = |_| Flow::Continue;
2424
let any = LinksConstants::new().any;
25+
let bg_links = background_links();
2526
group.bench_function(id, |bencher| {
2627
bench!(|fork| as B {
27-
for index in 1..=1_000 {
28-
elapsed! {fork.each_by([index, any, any], handler)};
29-
}
30-
for index in 1_001..=2_000 {
31-
elapsed! {fork.each_by([index, any, any], handler)};
32-
}
33-
for index in 2_001..=BACKGROUND_LINKS {
28+
for index in 1..=bg_links {
3429
elapsed! {fork.each_by([index, any, any], handler)};
3530
}
3631
})(bencher, &mut benched);

rust/benches/benchmarks/each/incoming.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use {
88
split::{self, DataPart, IndexPart},
99
unit, Doublets,
1010
},
11-
linkspsql::{bench, connect, Benched, Client, Exclusive, Fork, Transaction},
11+
linkspsql::{background_links, bench, connect, Benched, Client, Exclusive, Fork, Transaction},
1212
std::{
1313
alloc::Global,
1414
time::{Duration, Instant},
@@ -22,15 +22,10 @@ fn bench<B: Benched + Doublets<usize>>(
2222
) {
2323
let handler = |_| Flow::Continue;
2424
let any = LinksConstants::new().any;
25+
let bg_links = background_links();
2526
group.bench_function(id, |bencher| {
2627
bench!(|fork| as B {
27-
for index in 1..=1_000 {
28-
elapsed! {fork.each_by([any, any, index], handler)};
29-
}
30-
for index in 1_001..=2_000 {
31-
elapsed! {fork.each_by([any, any, index], handler)};
32-
}
33-
for index in 2_001..=BACKGROUND_LINKS {
28+
for index in 1..=bg_links {
3429
elapsed! {fork.each_by([any, any, index], handler)};
3530
}
3631
})(bencher, &mut benched);

rust/benches/benchmarks/each/outgoing.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use {
88
split::{self, DataPart, IndexPart},
99
unit, Doublets,
1010
},
11-
linkspsql::{bench, connect, Benched, Client, Exclusive, Fork, Transaction},
11+
linkspsql::{background_links, bench, connect, Benched, Client, Exclusive, Fork, Transaction},
1212
std::{
1313
alloc::Global,
1414
time::{Duration, Instant},
@@ -22,15 +22,10 @@ fn bench<B: Benched + Doublets<usize>>(
2222
) {
2323
let handler = |_| Flow::Continue;
2424
let any = LinksConstants::new().any;
25+
let bg_links = background_links();
2526
group.bench_function(id, |bencher| {
2627
bench!(|fork| as B {
27-
for index in 1..=1_000 {
28-
let _ = elapsed! {fork.each_by([any, index, any], handler)};
29-
}
30-
for index in 1_001..=2_000 {
31-
let _ = elapsed! {fork.each_by([any, index, any], handler)};
32-
}
33-
for index in 2_001..=BACKGROUND_LINKS {
28+
for index in 1..=bg_links {
3429
let _ = elapsed! {fork.each_by([any, index, any], handler)};
3530
}
3631
})(bencher, &mut benched);

rust/benches/benchmarks/update.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use {
66
mem::{Alloc, FileMapped}, split, split::{DataPart, IndexPart},
77
unit, unit::LinkPart,
88
},
9-
linkspsql::{BACKGROUND_LINKS, bench, Benched, Transaction, Exclusive, connect, Client, Fork},
9+
linkspsql::{background_links, benchmark_links, bench, Benched, Transaction, Exclusive, connect, Client, Fork},
1010
std::{alloc::Global, time::{Duration, Instant}},
1111
};
1212

@@ -15,9 +15,11 @@ fn bench<B: Benched + Doublets<usize>>(
1515
id: &str,
1616
mut benched: B,
1717
) {
18+
let bg_links = background_links();
19+
let links = benchmark_links();
1820
group.bench_function(id, |bencher| {
1921
bench!(|fork| as B {
20-
for id in BACKGROUND_LINKS - 999..=BACKGROUND_LINKS {
22+
for id in bg_links - (links - 1)..=bg_links {
2123
let _ = elapsed! {fork.update(id, 0, 0)?};
2224
let _ = elapsed! {fork.update(id, id, id)?};
2325
}

rust/src/lib.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ macro_rules! bench {
1515
}};
1616
}
1717
crate::tri! {
18-
use linkspsql::BACKGROUND_LINKS;
18+
let background_links = linkspsql::background_links();
1919
for _iter in 0..iters {
2020
let mut $fork: Fork<$B> = Benched::fork(&mut *benched);
21-
for _ in 0..BACKGROUND_LINKS {
21+
for _ in 0..background_links {
2222
let _ = $fork.create_point()?;
2323
}
2424
$($body)*
@@ -30,15 +30,14 @@ macro_rules! bench {
3030
}
3131
}
3232

33-
use doublets::Doublets;
3433
pub use {
3534
benched::Benched, client::Client, exclusive::Exclusive, fork::Fork, transaction::Transaction,
3635
};
3736

3837
use {
3938
doublets::{data::LinkType, mem::FileMapped},
4039
postgres::NoTls,
41-
std::{error, fs::File, io, result},
40+
std::{env, error, fs::File, io, result},
4241
};
4342

4443
mod benched;
@@ -49,7 +48,25 @@ mod transaction;
4948

5049
pub type Result<T, E = Box<dyn error::Error + Sync + Send>> = result::Result<T, E>;
5150

52-
pub const BACKGROUND_LINKS: usize = 3_000;
51+
/// Number of background links to create before each benchmark iteration.
52+
/// Configurable via BENCHMARK_BACKGROUND_LINKS environment variable.
53+
/// Default: 3000 (for local testing), CI uses 100 for PRs and 100000 for main branch.
54+
pub fn background_links() -> usize {
55+
env::var("BENCHMARK_BACKGROUND_LINKS")
56+
.ok()
57+
.and_then(|s| s.parse().ok())
58+
.unwrap_or(3_000)
59+
}
60+
61+
/// Number of links to create/update/delete in each benchmark operation.
62+
/// Configurable via BENCHMARK_LINKS environment variable.
63+
/// Default: 1000 (for local testing), CI uses 10 for PRs and 1000 for main branch.
64+
pub fn benchmark_links() -> usize {
65+
env::var("BENCHMARK_LINKS")
66+
.ok()
67+
.and_then(|s| s.parse().ok())
68+
.unwrap_or(1_000)
69+
}
5370
const PARAMS: &str = "user=postgres dbname=postgres password=postgres host=localhost port=5432";
5471

5572
pub fn connect<T: LinkType>() -> Result<Client<T>> {

0 commit comments

Comments
 (0)