diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index 119286b..17072d7 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -17,9 +17,7 @@ jobs: benchmarks: name: Run Benchmarks runs-on: ubuntu-latest - timeout-minutes: 60 - permissions: - contents: write + timeout-minutes: 15 steps: - name: Checkout repository @@ -32,9 +30,6 @@ jobs: with: components: clippy, rustfmt - - name: Install cargo-hack - run: cargo install cargo-hack - - name: Cache cargo registry uses: actions/cache@v4 with: @@ -46,19 +41,18 @@ jobs: ${{ runner.os }}-cargo- - name: Build benchmarks - run: cargo build --benches --all-features + run: cargo build --benches --release - - name: Run benchmarks - run: cargo bench --all-features 2>&1 | tee bench_output.txt - continue-on-error: true + - name: Run benchmarks (CI mode) + run: cargo bench --bench write_bench --bench read_bench --bench scan_bench --bench mixed_bench --bench stress_bench -- --noplot + env: + CI: true - name: Upload benchmark results uses: actions/upload-artifact@v4 with: name: benchmark-results - path: | - bench_output.txt - target/criterion + path: target/criterion/benchmark-results.json retention-days: 30 - name: Generate benchmark summary @@ -120,77 +114,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Run clippy on benchmarks - run: cargo clippy --all-targets --all-features -- -D warnings + run: cargo clippy --all-targets -- -D warnings - name: Format check run: cargo fmt --all -- --check - - benchmark-comparison: - name: Compare with Baseline - runs-on: ubuntu-latest - needs: benchmarks - if: github.event_name == 'pull_request' - steps: - - name: Download baseline results - continue-on-error: true - uses: actions/download-artifact@v4 - with: - name: baseline-results - path: baseline - - - name: Download current results - continue-on-error: true - uses: actions/download-artifact@v4 - with: - name: benchmark-results - path: current - - - name: Compare benchmarks - run: | - if [ -f baseline/bench_output.txt ] && [ -f current/bench_output.txt ]; then - echo "Comparing benchmarks..." - # TODO: Implement actual comparison logic with cargo-benchcmp or similar - else - echo "No baseline available yet — skipping comparison. This is expected on the first run." - fi - - - name: Upload comparison report - if: always() - uses: actions/upload-artifact@v4 - with: - name: comparison-report - path: comparison-report.md - if-no-files-found: ignore - - performance-regression: - name: Check Performance Regressions - runs-on: ubuntu-latest - if: github.event_name == 'push' - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable - - - name: Set up benchmarks - run: | - cargo install cargo-benchcmp - - - name: Restore baseline - uses: actions/cache@v4 - with: - path: .baseline - key: ${{ runner.os }}-benchmark-baseline - - - name: Run baseline benchmarks - run: cargo bench --all-features -- --output-format benchstat - continue-on-error: true - env: - CI: true - - - name: Check for regressions > 10% - run: | - echo "Checking for performance regressions..." - # TODO: Implement regression detection - # This would typically compare against stored baselines diff --git a/benches/mixed_bench.rs b/benches/mixed_bench.rs index 87b670e..0daad49 100644 --- a/benches/mixed_bench.rs +++ b/benches/mixed_bench.rs @@ -4,6 +4,17 @@ use rand::Rng; use std::path::PathBuf; use tempfile::TempDir; +fn configure_criterion() -> Criterion { + let mut c = Criterion::default(); + if std::env::var("CI").is_ok() { + c = c + .sample_size(10) + .warm_up_time(std::time::Duration::from_secs(1)) + .measurement_time(std::time::Duration::from_secs(3)); + } + c +} + fn setup_temp_dir(name: &str) -> (TempDir, PathBuf) { let temp_dir = TempDir::new().expect("Failed to create temp dir"); let path = temp_dir.path().join(name); @@ -32,7 +43,12 @@ fn generate_value(index: usize, value_size: usize) -> Vec { /// Benchmark YCSB Type A: 50% read, 50% write (uniform) fn bench_ycsb_type_a(c: &mut Criterion) { - for num_keys in [10_000usize, 100_000] { + let num_keys_arr: Vec = if std::env::var("CI").is_ok() { + vec![10_000] + } else { + vec![10_000, 100_000] + }; + for num_keys in num_keys_arr { let mut group = c.benchmark_group("ycsb_type_a"); group.throughput(Throughput::Elements(1000)); @@ -83,7 +99,12 @@ fn bench_ycsb_type_a(c: &mut Criterion) { /// Benchmark YCSB Type B: 95% read, 5% write (read-heavy) fn bench_ycsb_type_b(c: &mut Criterion) { - for num_keys in [10_000usize, 100_000] { + let num_keys_arr: Vec = if std::env::var("CI").is_ok() { + vec![10_000] + } else { + vec![10_000, 100_000] + }; + for num_keys in num_keys_arr { let mut group = c.benchmark_group("ycsb_type_b"); group.throughput(Throughput::Elements(1000)); @@ -138,7 +159,12 @@ fn bench_ycsb_type_b(c: &mut Criterion) { /// Benchmark YCSB Type C: 100% read (read-only) fn bench_ycsb_type_c(c: &mut Criterion) { - for num_keys in [10_000usize, 100_000, 1_000_000] { + let num_keys_arr: Vec = if std::env::var("CI").is_ok() { + vec![10_000, 100_000] + } else { + vec![10_000, 100_000, 1_000_000] + }; + for num_keys in num_keys_arr { let mut group = c.benchmark_group("ycsb_type_c"); group.throughput(Throughput::Elements(1000)); @@ -192,7 +218,12 @@ fn bench_ycsb_type_c(c: &mut Criterion) { /// Benchmark balanced workload: 50% read, 50% write fn bench_workload_balanced(c: &mut Criterion) { - for num_keys in [10_000usize, 100_000] { + let num_keys_arr: Vec = if std::env::var("CI").is_ok() { + vec![10_000] + } else { + vec![10_000, 100_000] + }; + for num_keys in num_keys_arr { let mut group = c.benchmark_group("workload_balanced"); group.throughput(Throughput::Elements(1000)); @@ -246,7 +277,12 @@ fn bench_workload_balanced(c: &mut Criterion) { /// Benchmark read-heavy workload fn bench_workload_read_heavy(c: &mut Criterion) { - for num_keys in [10_000usize, 100_000] { + let num_keys_arr: Vec = if std::env::var("CI").is_ok() { + vec![10_000] + } else { + vec![10_000, 100_000] + }; + for num_keys in num_keys_arr { let mut group = c.benchmark_group("workload_read_heavy"); group.throughput(Throughput::Elements(1000)); @@ -301,7 +337,12 @@ fn bench_workload_read_heavy(c: &mut Criterion) { /// Benchmark write-heavy workload fn bench_workload_write_heavy(c: &mut Criterion) { - for num_keys in [10_000usize, 100_000] { + let num_keys_arr: Vec = if std::env::var("CI").is_ok() { + vec![10_000] + } else { + vec![10_000, 100_000] + }; + for num_keys in num_keys_arr { let mut group = c.benchmark_group("workload_write_heavy"); group.throughput(Throughput::Bytes(100)); @@ -352,13 +393,9 @@ fn bench_workload_write_heavy(c: &mut Criterion) { } criterion_group!( - mixed_benches, - bench_ycsb_type_a, - bench_ycsb_type_b, - bench_ycsb_type_c, - bench_workload_balanced, - bench_workload_read_heavy, - bench_workload_write_heavy, + name = mixed_benches; + config = configure_criterion(); + targets = bench_ycsb_type_a, bench_ycsb_type_b, bench_ycsb_type_c, bench_workload_balanced, bench_workload_read_heavy, bench_workload_write_heavy ); criterion_main!(mixed_benches); diff --git a/benches/read_bench.rs b/benches/read_bench.rs index 12d1230..78d69f1 100644 --- a/benches/read_bench.rs +++ b/benches/read_bench.rs @@ -3,6 +3,17 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Through use std::path::PathBuf; use tempfile::TempDir; +fn configure_criterion() -> Criterion { + let mut c = Criterion::default(); + if std::env::var("CI").is_ok() { + c = c + .sample_size(10) + .warm_up_time(std::time::Duration::from_secs(1)) + .measurement_time(std::time::Duration::from_secs(3)); + } + c +} + /// Setup a temporary directory for benchmark testing fn setup_temp_dir(name: &str) -> (TempDir, PathBuf) { let temp_dir = TempDir::new().expect("Failed to create temp dir"); @@ -35,7 +46,11 @@ fn generate_value(index: usize, value_size: usize) -> Vec { /// Benchmark read operations with all keys in MemTable fn bench_read_memtable(c: &mut Criterion) { - let num_keys_arr = [1_000usize, 10_000, 100_000, 1_000_000]; + let num_keys_arr: Vec = if std::env::var("CI").is_ok() { + vec![1_000, 10_000] + } else { + vec![1_000, 10_000, 100_000, 1_000_000] + }; for &num_keys in &num_keys_arr { let mut group = c.benchmark_group("read_memtable"); group.throughput(Throughput::Elements(num_keys as u64)); @@ -83,7 +98,12 @@ fn bench_read_memtable(c: &mut Criterion) { /// Benchmark read operations with all keys in SSTable (cold cache) fn bench_read_sstable_cold(c: &mut Criterion) { - for num_keys in [1_000usize, 10_000, 100_000] { + let num_keys_arr: Vec = if std::env::var("CI").is_ok() { + vec![1_000, 10_000] + } else { + vec![1_000, 10_000, 100_000] + }; + for num_keys in num_keys_arr { let mut group = c.benchmark_group("read_sstable_cold"); group.throughput(Throughput::Elements(num_keys as u64)); @@ -96,7 +116,7 @@ fn bench_read_sstable_cold(c: &mut Criterion) { LsmConfig::builder() .dir_path(data_dir.clone()) .memtable_max_size(nk * 110 / 2) - .block_cache_size_mb(0) + .block_cache_size_mb(1) .build() .unwrap(), ) @@ -131,7 +151,12 @@ fn bench_read_sstable_cold(c: &mut Criterion) { /// Benchmark read operations with cache warmed up fn bench_read_sstable_warm(c: &mut Criterion) { - for num_keys in [1_000usize, 10_000, 100_000] { + let num_keys_arr: Vec = if std::env::var("CI").is_ok() { + vec![1_000, 10_000] + } else { + vec![1_000, 10_000, 100_000] + }; + for num_keys in num_keys_arr { let mut group = c.benchmark_group("read_sstable_warm"); group.throughput(Throughput::Elements(num_keys as u64)); @@ -184,7 +209,12 @@ fn bench_read_sstable_warm(c: &mut Criterion) { /// Benchmark Bloom filter effectiveness fn bench_bloom_filter(c: &mut Criterion) { - for num_keys in [10_000usize, 100_000, 1_000_000] { + let num_keys_arr: Vec = if std::env::var("CI").is_ok() { + vec![10_000, 100_000] + } else { + vec![10_000, 100_000, 1_000_000] + }; + for num_keys in num_keys_arr { let mut group = c.benchmark_group("bloom_filter"); group.throughput(Throughput::Elements(num_keys as u64)); @@ -197,7 +227,7 @@ fn bench_bloom_filter(c: &mut Criterion) { LsmConfig::builder() .dir_path(data_dir.clone()) .memtable_max_size(nk * 110 / 2) - .block_cache_size_mb(0) + .block_cache_size_mb(1) .build() .unwrap(), ) @@ -271,7 +301,7 @@ fn bench_read_latency(c: &mut Criterion) { LsmConfig::builder() .dir_path(data_dir.clone()) .memtable_max_size(1_000 * 110 / 2) - .block_cache_size_mb(0) + .block_cache_size_mb(1) .build() .unwrap(), ) @@ -301,7 +331,11 @@ fn bench_read_latency(c: &mut Criterion) { /// Benchmark sequential scan performance fn bench_scan_sequential(c: &mut Criterion) { - let num_keys_arr = [1_000usize, 10_000, 100_000]; + let num_keys_arr: Vec = if std::env::var("CI").is_ok() { + vec![1_000, 10_000] + } else { + vec![1_000, 10_000, 100_000] + }; for &num_keys in &num_keys_arr { let mut group = c.benchmark_group("scan_sequential"); group.throughput(Throughput::Elements(num_keys as u64)); @@ -330,7 +364,7 @@ fn bench_scan_sequential(c: &mut Criterion) { engine.flush_memtable().unwrap(); b.iter(|| { - let results = engine.scan().unwrap(); + let results = engine.scan_cf("default", None, None, None).unwrap(); assert_eq!(results.len(), nk); }); @@ -344,13 +378,9 @@ fn bench_scan_sequential(c: &mut Criterion) { } criterion_group!( - read_benches, - bench_read_memtable, - bench_read_sstable_cold, - bench_read_sstable_warm, - bench_bloom_filter, - bench_read_latency, - bench_scan_sequential, + name = read_benches; + config = configure_criterion(); + targets = bench_read_memtable, bench_read_sstable_cold, bench_read_sstable_warm, bench_bloom_filter, bench_read_latency, bench_scan_sequential ); criterion_main!(read_benches); diff --git a/benches/scan_bench.rs b/benches/scan_bench.rs index 2eb41de..e321182 100644 --- a/benches/scan_bench.rs +++ b/benches/scan_bench.rs @@ -3,6 +3,17 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Through use std::path::PathBuf; use tempfile::TempDir; +fn configure_criterion() -> Criterion { + let mut c = Criterion::default(); + if std::env::var("CI").is_ok() { + c = c + .sample_size(10) + .warm_up_time(std::time::Duration::from_secs(1)) + .measurement_time(std::time::Duration::from_secs(3)); + } + c +} + fn setup_temp_dir(name: &str) -> (TempDir, PathBuf) { let temp_dir = TempDir::new().expect("Failed to create temp dir"); let path = temp_dir.path().join(name); @@ -31,7 +42,12 @@ fn generate_value(index: usize, value_size: usize) -> Vec { } fn bench_full_scan(c: &mut Criterion) { - for num_keys in [1_000usize, 10_000, 100_000] { + let num_keys_arr: Vec = if std::env::var("CI").is_ok() { + vec![1_000, 10_000] + } else { + vec![1_000, 10_000, 100_000] + }; + for num_keys in num_keys_arr { let mut group = c.benchmark_group("full_scan"); group.throughput(Throughput::Elements(num_keys as u64)); @@ -57,7 +73,7 @@ fn bench_full_scan(c: &mut Criterion) { } b.iter(|| { - let results = engine.scan().unwrap(); + let results = engine.scan_cf("default", None, None, None).unwrap(); assert_eq!(results.len(), nk); }); @@ -71,7 +87,14 @@ fn bench_full_scan(c: &mut Criterion) { } fn bench_range_scan(c: &mut Criterion) { - for scan_size in [100usize, 1_000, 10_000, 100_000] { + let is_ci = std::env::var("CI").is_ok(); + let total_keys = if is_ci { 100_000usize } else { 1_000_000usize }; + let scan_sizes: Vec = if is_ci { + vec![100, 1_000] + } else { + vec![100, 1_000, 10_000, 100_000] + }; + for scan_size in scan_sizes { let mut group = c.benchmark_group(format!("range_scan_{}", scan_size)); group.throughput(Throughput::Elements(scan_size as u64)); @@ -79,7 +102,6 @@ fn bench_range_scan(c: &mut Criterion) { BenchmarkId::from_parameter(scan_size), &scan_size, |b, &_ss| { - let total_keys = 1_000_000usize; let (temp_dir, data_dir) = setup_temp_dir("range_scan"); let mut engine = apexstore::LsmEngine::new( LsmConfig::builder() @@ -124,7 +146,14 @@ fn bench_range_scan(c: &mut Criterion) { } fn bench_prefix_scan(c: &mut Criterion) { - for prefix_size in [100usize, 1_000, 10_000] { + let is_ci = std::env::var("CI").is_ok(); + let total_keys = if is_ci { 10_000usize } else { 100_000usize }; + let prefix_sizes: Vec = if is_ci { + vec![100, 1_000] + } else { + vec![100, 1_000, 10_000] + }; + for prefix_size in prefix_sizes { let mut group = c.benchmark_group(format!("prefix_scan_{}", prefix_size)); group.throughput(Throughput::Elements(prefix_size as u64)); @@ -132,7 +161,6 @@ fn bench_prefix_scan(c: &mut Criterion) { BenchmarkId::from_parameter(prefix_size), &prefix_size, |b, &_ps| { - let total_keys = 100_000usize; let (temp_dir, data_dir) = setup_temp_dir("prefix_scan"); let mut engine = apexstore::LsmEngine::new( LsmConfig::builder() @@ -168,7 +196,12 @@ fn bench_prefix_scan(c: &mut Criterion) { } fn bench_iteration_sorted(c: &mut Criterion) { - for num_keys in [1_000usize, 10_000, 100_000] { + let num_keys_arr: Vec = if std::env::var("CI").is_ok() { + vec![1_000, 10_000] + } else { + vec![1_000, 10_000, 100_000] + }; + for &num_keys in &num_keys_arr { let mut group = c.benchmark_group("iteration_sorted"); group.throughput(Throughput::Elements(num_keys as u64)); @@ -194,7 +227,7 @@ fn bench_iteration_sorted(c: &mut Criterion) { } b.iter(|| { - let results = engine.scan().unwrap(); + let results = engine.scan_cf("default", None, None, None).unwrap(); for i in 1..results.len() { assert!(results[i - 1].0 <= results[i].0); } @@ -211,12 +244,18 @@ fn bench_iteration_sorted(c: &mut Criterion) { } fn bench_scan_with_limit(c: &mut Criterion) { - for limit in [10usize, 100, 1_000, 10_000] { + let is_ci = std::env::var("CI").is_ok(); + let total_keys = if is_ci { 100_000usize } else { 1_000_000usize }; + let limits: Vec = if is_ci { + vec![10, 100, 1_000] + } else { + vec![10, 100, 1_000, 10_000] + }; + for limit in limits { let mut group = c.benchmark_group(format!("scan_limit_{}", limit)); group.throughput(Throughput::Elements(limit as u64)); group.bench_with_input(BenchmarkId::from_parameter(limit), &limit, |b, &_l| { - let total_keys = 1_000_000usize; let (temp_dir, data_dir) = setup_temp_dir("scan_limit"); let mut engine = apexstore::LsmEngine::new( LsmConfig::builder() @@ -248,7 +287,14 @@ fn bench_scan_with_limit(c: &mut Criterion) { } fn bench_scan_pagination(c: &mut Criterion) { - for num_pages in [10usize, 100, 1_000] { + let is_ci = std::env::var("CI").is_ok(); + let total_keys = if is_ci { 10_000usize } else { 100_000usize }; + let num_pages_arr: Vec = if is_ci { + vec![10, 100] + } else { + vec![10, 100, 1_000] + }; + for num_pages in num_pages_arr { let mut group = c.benchmark_group("scan_pagination"); group.throughput(Throughput::Elements((num_pages * 100) as u64)); @@ -256,7 +302,6 @@ fn bench_scan_pagination(c: &mut Criterion) { BenchmarkId::from_parameter(num_pages), &num_pages, |b, &_np| { - let total_keys = 100_000usize; let page_size = 100usize; let (temp_dir, data_dir) = setup_temp_dir("scan_pagination"); let mut engine = apexstore::LsmEngine::new( @@ -304,7 +349,12 @@ fn bench_scan_pagination(c: &mut Criterion) { } fn bench_sstable_layer_scan(c: &mut Criterion) { - for layer_count in [1usize, 3, 10, 30] { + let layer_counts: Vec = if std::env::var("CI").is_ok() { + vec![1, 3, 10] + } else { + vec![1, 3, 10, 30] + }; + for layer_count in layer_counts { let mut group = c.benchmark_group(format!("sstable_layer_{}", layer_count)); group.bench_with_input( @@ -332,7 +382,7 @@ fn bench_sstable_layer_scan(c: &mut Criterion) { } b.iter(|| { - let results = engine.scan().unwrap(); + let results = engine.scan_cf("default", None, None, None).unwrap(); assert!(results.len() >= keys_per_layer); }); @@ -346,14 +396,9 @@ fn bench_sstable_layer_scan(c: &mut Criterion) { } criterion_group!( - scan_benches, - bench_full_scan, - bench_range_scan, - bench_prefix_scan, - bench_iteration_sorted, - bench_scan_with_limit, - bench_scan_pagination, - bench_sstable_layer_scan, + name = scan_benches; + config = configure_criterion(); + targets = bench_full_scan, bench_range_scan, bench_prefix_scan, bench_iteration_sorted, bench_scan_with_limit, bench_scan_pagination, bench_sstable_layer_scan ); criterion_main!(scan_benches); diff --git a/benches/stress_bench.rs b/benches/stress_bench.rs index dab6246..82ac876 100644 --- a/benches/stress_bench.rs +++ b/benches/stress_bench.rs @@ -3,6 +3,17 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use std::path::PathBuf; use tempfile::TempDir; +fn configure_criterion() -> Criterion { + let mut c = Criterion::default(); + if std::env::var("CI").is_ok() { + c = c + .sample_size(10) + .warm_up_time(std::time::Duration::from_secs(1)) + .measurement_time(std::time::Duration::from_secs(3)); + } + c +} + fn setup_temp_dir(name: &str) -> (TempDir, PathBuf) { let temp_dir = TempDir::new().expect("Failed to create temp dir"); let path = temp_dir.path().join(name); @@ -32,6 +43,9 @@ fn generate_value(index: usize, value_size: usize) -> Vec { /// Benchmark with very large dataset (1M keys) fn bench_large_dataset_1m(c: &mut Criterion) { + if std::env::var("CI").is_ok() { + return; // Skip in CI - too expensive + } let mut group = c.benchmark_group("large_dataset_1m"); group.bench_with_input(BenchmarkId::from_parameter("1m_keys"), &(), |b, &_| { @@ -75,12 +89,15 @@ fn bench_large_dataset_1m(c: &mut Criterion) { fn bench_concurrent_access(c: &mut Criterion) { use std::sync::{Arc, Mutex}; - let thread_count = [1, 2, 4]; - - for &threads in &thread_count { + let thread_count: Vec = if std::env::var("CI").is_ok() { + vec![1, 2] + } else { + vec![1, 2, 4] + }; + for threads in thread_count { let mut group = c.benchmark_group(format!("concurrent_{}_threads", threads)); - group.bench_with_input(BenchmarkId::from_parameter(threads), &threads, |b, &_t| { + group.bench_with_input(BenchmarkId::from_parameter(threads), &threads, |b, _t| { let (temp_dir, data_dir) = setup_temp_dir("concurrent"); let mut engine = apexstore::LsmEngine::new( LsmConfig::builder() @@ -172,8 +189,11 @@ fn bench_memory_pressure(c: &mut Criterion) { /// Benchmark with many SSTables (thousands of layers) fn bench_many_sstables(c: &mut Criterion) { - let sstable_counts = [10, 50, 100]; - + let sstable_counts: Vec = if std::env::var("CI").is_ok() { + vec![10, 50] + } else { + vec![10, 50, 100] + }; for &sstable_count in &sstable_counts { let mut group = c.benchmark_group(format!("many_sstables_{}", sstable_count)); @@ -221,8 +241,11 @@ fn bench_many_sstables(c: &mut Criterion) { /// Benchmark cache thrashing scenario fn bench_cache_thrashing(c: &mut Criterion) { - let cache_sizes = [16, 64, 128]; // MB - + let cache_sizes: Vec = if std::env::var("CI").is_ok() { + vec![16, 64] + } else { + vec![16, 64, 128] + }; for &cache_mb in &cache_sizes { let mut group = c.benchmark_group(format!("cache_thrash_{}MB", cache_mb)); @@ -337,14 +360,9 @@ fn bench_delete_operations(c: &mut Criterion) { } criterion_group!( - stress_benches, - bench_large_dataset_1m, - bench_concurrent_access, - bench_memory_pressure, - bench_many_sstables, - bench_cache_thrashing, - bench_key_updates, - bench_delete_operations, + name = stress_benches; + config = configure_criterion(); + targets = bench_large_dataset_1m, bench_concurrent_access, bench_memory_pressure, bench_many_sstables, bench_cache_thrashing, bench_key_updates, bench_delete_operations ); criterion_main!(stress_benches); diff --git a/benches/write_bench.rs b/benches/write_bench.rs index 44e528b..36ae387 100644 --- a/benches/write_bench.rs +++ b/benches/write_bench.rs @@ -3,6 +3,17 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Through use std::path::PathBuf; use tempfile::TempDir; +fn configure_criterion() -> Criterion { + let mut c = Criterion::default(); + if std::env::var("CI").is_ok() { + c = c + .sample_size(10) + .warm_up_time(std::time::Duration::from_secs(1)) + .measurement_time(std::time::Duration::from_secs(3)); + } + c +} + /// Setup a temporary directory for benchmark testing fn setup_temp_dir(name: &str) -> (TempDir, PathBuf) { let temp_dir = TempDir::new().expect("Failed to create temp dir"); @@ -107,7 +118,12 @@ fn bench_batch_write(c: &mut Criterion) { /// Benchmark memtable flush performance fn bench_memtable_flush(c: &mut Criterion) { - for memtable_size in [8 * 1024 * 1024, 16 * 1024 * 1024, 32 * 1024 * 1024] { + let memtable_sizes: Vec = if std::env::var("CI").is_ok() { + vec![8 * 1024 * 1024] + } else { + vec![8 * 1024 * 1024, 16 * 1024 * 1024, 32 * 1024 * 1024] + }; + for memtable_size in memtable_sizes { let mut group = c.benchmark_group(format!("memtable_flush_{}", memtable_size / 1024 / 1024)); group.throughput(Throughput::Bytes(memtable_size as u64)); @@ -239,12 +255,9 @@ fn bench_write_by_size(c: &mut Criterion) { } criterion_group!( - write_benches, - bench_single_write, - bench_batch_write, - bench_memtable_flush, - bench_sstable_flush, - bench_write_by_size, + name = write_benches; + config = configure_criterion(); + targets = bench_single_write, bench_batch_write, bench_memtable_flush, bench_sstable_flush, bench_write_by_size ); criterion_main!(write_benches); diff --git a/src/core/engine/mod.rs b/src/core/engine/mod.rs index 0321caf..780d501 100644 --- a/src/core/engine/mod.rs +++ b/src/core/engine/mod.rs @@ -259,7 +259,7 @@ impl Engine { } pub fn scan(&self) -> crate::infra::error::Result, Vec)>> { - self.scan_cf("default", None, None, None) + self.scan_cf("default", None, None, Some(DEFAULT_SCAN_LIMIT)) } pub fn scan_cf(