|
| 1 | +# NexumDB Core Performance Benchmarks |
| 2 | + |
| 3 | +This document provides an overview of the comprehensive benchmarking suite implemented for `nexum_core`. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The benchmarking suite uses [Criterion.rs](https://github.com/bheisler/criterion.rs) to provide: |
| 8 | +- Statistical analysis of performance metrics |
| 9 | +- Regression detection across code changes |
| 10 | +- HTML reports with interactive charts |
| 11 | +- CI integration for automated performance monitoring |
| 12 | + |
| 13 | +## Quick Start |
| 14 | + |
| 15 | +```bash |
| 16 | +# Run all benchmarks |
| 17 | +cd nexum_core |
| 18 | +cargo bench |
| 19 | + |
| 20 | +# Run specific benchmark suite |
| 21 | +cargo bench --bench storage_bench |
| 22 | + |
| 23 | +# Use the benchmark runner script (Linux/macOS) |
| 24 | +./run_benchmarks.sh |
| 25 | +``` |
| 26 | + |
| 27 | +## Benchmark Suites |
| 28 | + |
| 29 | +### 1. Storage Engine (`storage_bench.rs`) |
| 30 | +- **Write Throughput**: 100 to 100,000 sequential writes |
| 31 | +- **Read Throughput**: 100 to 100,000 sequential reads |
| 32 | +- **Mixed Workload**: Various read/write ratios (70/30, 50/50, 30/70) |
| 33 | +- **Prefix Scanning**: Scan performance with different prefix sizes |
| 34 | +- **Persistence**: Flush and durability operations |
| 35 | + |
| 36 | +### 2. SQL Parser (`sql_bench.rs`) |
| 37 | +- **CREATE TABLE**: Simple and complex table definitions |
| 38 | +- **INSERT**: 1 to 1,000 row batch inserts |
| 39 | +- **SELECT**: Simple to complex query parsing |
| 40 | +- **Mixed Workload**: Realistic SQL statement patterns |
| 41 | +- **Error Handling**: Invalid SQL processing performance |
| 42 | +- **Large Queries**: 10,000+ row INSERT statements |
| 43 | + |
| 44 | +### 3. Query Executor (`executor_bench.rs`) |
| 45 | +- **Simple SELECT**: Table scanning with 100 to 10,000 records |
| 46 | +- **Filtered SELECT**: WHERE clause evaluation performance |
| 47 | +- **INSERT Operations**: 1 to 1,000 row batch inserts |
| 48 | +- **CREATE TABLE**: Table creation overhead |
| 49 | +- **Mixed Workload**: Typical application usage patterns |
| 50 | +- **Large Datasets**: 50,000 to 100,000 record operations |
| 51 | + |
| 52 | +### 4. Filter Evaluation (`filter_bench.rs`) |
| 53 | +- **Simple Comparisons**: =, >, <, >=, <=, != operations |
| 54 | +- **Complex Expressions**: AND, OR, nested conditions |
| 55 | +- **LIKE Patterns**: %, _ wildcard matching |
| 56 | +- **IN Lists**: 5 to 100 item list performance |
| 57 | +- **BETWEEN Ranges**: Numeric and text range filtering |
| 58 | +- **Batch Evaluation**: 10,000 row filter processing |
| 59 | + |
| 60 | +## Performance Targets |
| 61 | + |
| 62 | +| Component | Operation | Target Performance | |
| 63 | +|-----------|-----------|-------------------| |
| 64 | +| Storage | Write Throughput | >10,000 ops/sec | |
| 65 | +| Storage | Read Throughput | >50,000 ops/sec | |
| 66 | +| Storage | Mixed Workload | >5,000 ops/sec | |
| 67 | +| SQL Parser | Simple Queries | <1ms parse time | |
| 68 | +| SQL Parser | Complex Queries | <10ms parse time | |
| 69 | +| Executor | Table Scans | >1,000 records/ms | |
| 70 | +| Executor | Filtered Queries | >500 records/ms | |
| 71 | +| Filters | Simple Filters | <1μs per row | |
| 72 | +| Filters | Complex Filters | <10μs per row | |
| 73 | + |
| 74 | +## CI Integration |
| 75 | + |
| 76 | +Benchmarks run automatically on pull requests: |
| 77 | + |
| 78 | +1. **Baseline Comparison**: Compare against main branch |
| 79 | +2. **Regression Detection**: Identify performance degradations |
| 80 | +3. **Report Generation**: Create performance summaries |
| 81 | +4. **Artifact Upload**: Store detailed results |
| 82 | + |
| 83 | +### CI Workflow |
| 84 | +```yaml |
| 85 | +benchmarks: |
| 86 | + name: Rust benchmarks |
| 87 | + runs-on: ubuntu-latest |
| 88 | + if: github.event_name == 'pull_request' |
| 89 | + # ... runs benchmarks and compares results |
| 90 | +``` |
| 91 | + |
| 92 | +## Interpreting Results |
| 93 | + |
| 94 | +### Criterion Output |
| 95 | +``` |
| 96 | +storage_write/sequential_writes/1000 |
| 97 | + time: [2.1234 ms 2.1456 ms 2.1678 ms] |
| 98 | + thrpt: [461.23 Kelem/s 466.12 Kelem/s 470.89 Kelem/s] |
| 99 | +``` |
| 100 | + |
| 101 | +- **time**: Mean execution time with confidence interval |
| 102 | +- **thrpt**: Throughput (elements per second) |
| 103 | +- **change**: Performance change from previous run |
| 104 | + |
| 105 | +### HTML Reports |
| 106 | +- Interactive charts showing performance trends |
| 107 | +- Statistical analysis with confidence intervals |
| 108 | +- Comparison between different benchmark runs |
| 109 | +- Detailed timing distributions |
| 110 | + |
| 111 | +## Development Workflow |
| 112 | + |
| 113 | +### Before Making Changes |
| 114 | +```bash |
| 115 | +# Establish baseline |
| 116 | +cargo bench > baseline_results.txt |
| 117 | +``` |
| 118 | + |
| 119 | +### After Making Changes |
| 120 | +```bash |
| 121 | +# Run benchmarks and compare |
| 122 | +cargo bench |
| 123 | +# Check for regressions in the output |
| 124 | +``` |
| 125 | + |
| 126 | +### Adding New Benchmarks |
| 127 | + |
| 128 | +1. **Create benchmark function**: |
| 129 | +```rust |
| 130 | +fn my_benchmark(c: &mut Criterion) { |
| 131 | + let mut group = c.benchmark_group("my_feature"); |
| 132 | + // ... benchmark implementation |
| 133 | + group.finish(); |
| 134 | +} |
| 135 | +``` |
| 136 | + |
| 137 | +2. **Add to criterion_group!**: |
| 138 | +```rust |
| 139 | +criterion_group!(benches, existing_bench, my_benchmark); |
| 140 | +``` |
| 141 | + |
| 142 | +3. **Update documentation** with performance targets |
| 143 | + |
| 144 | +## Optimization Guidelines |
| 145 | + |
| 146 | +### Storage Layer |
| 147 | +- Minimize allocations in hot paths |
| 148 | +- Use batch operations for bulk data |
| 149 | +- Optimize key encoding/decoding |
| 150 | +- Implement efficient caching |
| 151 | + |
| 152 | +### SQL Parser |
| 153 | +- Cache compiled regex patterns |
| 154 | +- Minimize string allocations |
| 155 | +- Use efficient AST construction |
| 156 | +- Implement parser combinators |
| 157 | + |
| 158 | +### Query Executor |
| 159 | +- Implement query plan caching |
| 160 | +- Use vectorized operations |
| 161 | +- Optimize memory access patterns |
| 162 | +- Implement parallel processing |
| 163 | + |
| 164 | +### Filter Evaluation |
| 165 | +- Short-circuit boolean expressions |
| 166 | +- Use SIMD for bulk operations |
| 167 | +- Optimize regex compilation |
| 168 | +- Implement predicate pushdown |
| 169 | + |
| 170 | +## Troubleshooting |
| 171 | + |
| 172 | +### Common Issues |
| 173 | + |
| 174 | +**Inconsistent Results** |
| 175 | +- Ensure stable system conditions |
| 176 | +- Close other applications |
| 177 | +- Run multiple times and average |
| 178 | + |
| 179 | +**Memory Issues** |
| 180 | +- Use `BatchSize::SmallInput` for large datasets |
| 181 | +- Monitor memory allocation patterns |
| 182 | +- Check for memory leaks |
| 183 | + |
| 184 | +**Compilation Errors** |
| 185 | +- Ensure all dependencies are available |
| 186 | +- Check feature flags |
| 187 | +- Verify Rust version compatibility |
| 188 | + |
| 189 | +### Performance Analysis Tools |
| 190 | + |
| 191 | +```bash |
| 192 | +# Detailed profiling |
| 193 | +cargo install flamegraph |
| 194 | +cargo flamegraph --bench storage_bench |
| 195 | + |
| 196 | +# Memory profiling |
| 197 | +cargo install heaptrack |
| 198 | +heaptrack cargo bench --bench storage_bench |
| 199 | + |
| 200 | +# Assembly analysis |
| 201 | +cargo asm nexum_core::storage::StorageEngine::set |
| 202 | +``` |
| 203 | + |
| 204 | +## Contributing |
| 205 | + |
| 206 | +When contributing benchmarks: |
| 207 | + |
| 208 | +1. **Follow existing patterns** in benchmark structure |
| 209 | +2. **Include realistic test data** representative of actual usage |
| 210 | +3. **Document performance expectations** and targets |
| 211 | +4. **Test locally** before submitting PRs |
| 212 | +5. **Consider CI runtime** - keep benchmarks reasonably fast |
| 213 | + |
| 214 | +### Benchmark Checklist |
| 215 | +- [ ] Realistic test data and scenarios |
| 216 | +- [ ] Multiple input sizes tested |
| 217 | +- [ ] Appropriate throughput measurements |
| 218 | +- [ ] Documentation updated |
| 219 | +- [ ] Performance targets defined |
| 220 | +- [ ] CI integration tested |
| 221 | + |
| 222 | +## Resources |
| 223 | + |
| 224 | +- [Criterion.rs Documentation](https://bheisler.github.io/criterion.rs/book/) |
| 225 | +- [Rust Performance Book](https://nnethercote.github.io/perf-book/) |
| 226 | +- [Benchmarking Best Practices](https://github.com/bheisler/criterion.rs/blob/master/book/src/user_guide/advanced_configuration.md) |
0 commit comments