Skip to content

pascalporedda/sqlite-sqlx-rs-benchmark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQLite Edge Computing Benchmark Suite

A comprehensive benchmark suite demonstrating SQLite's performance characteristics for edge computing binaries using Rust and SQLX.

Overview

This project was done to validate the performance claims made in my blog post "SQLite at the Edge: When To Choose A Local Database Persistence Layer" by trying to re-implement a scenario I had at a client project. This benchmark measures:

  • Single vs Batch Insert Performance
  • Concurrent Read Performance
  • PRAGMA Optimization Impact
  • Index Performance Trade-offs
  • WAL Checkpoint Performance

Key Ideas

  • Dual-Pool Architecture: Separate read/write pools following SQLite best practices

  • Production-Grade Optimizations: Implements all PRAGMA settings from

  • this blog post

  • Comprehensive Metrics: Measures latency percentiles, throughput, and resource usage

  • File based database and comparision with in-memory db

Performance Targets

Based on the blog post research, this benchmark suite validates:

  • 10,000+ messages/second sustained throughput
  • Sub-millisecond query latency for indexed lookups
  • Concurrent read scaling with WAL mode
  • Batch insert optimization (100-1000x improvement over single inserts)

Quick Start

Prerequisites

  • Rust 1.70+
  • SQLite 3.38+

Installation

git clone https://github.com/yourusername/sqlx-sqlite-benchmark
cd sqlx-sqlite-benchmark
cargo build --release

Running the Demo

# Quick demonstration with 10,000 sensor readings (in-memory)
DATABASE_URL=sqlite::memory: cargo run --release -- --demo

# Demo with file database
DATABASE_URL=sqlite:demo.db cargo run --release -- --demo

Running Full Benchmarks

# Run complete benchmark suite (in-memory database)
DATABASE_URL=sqlite::memory: cargo run --release -- --benchmark

# Run with file database
DATABASE_URL=sqlite:benchmark.db cargo run --release -- --benchmark

# Custom configuration with reduced records for testing
DATABASE_URL=sqlite::memory: cargo run --release -- --benchmark \
  --iterations 3 \
  --total-records 10000

Database URL Format

The DATABASE_URL environment variable is required and supports:

  • In-memory database: sqlite::memory:
  • File database: sqlite:path/to/database.db

Important: Always set DATABASE_URL before running any commands. The application will exit with an error message if this is not set.

Benchmarks

Performance targets assume:

  • NVMe SSD storage (3-5x faster than SATA SSD)
  • 8GB+ RAM for effective page caching
  • Modern multi-core CPU
  • ext4 filesystem with noatime mount options

Performance Factors

  1. Storage Type: NVMe > SATA SSD > HDD (3-10x differences)
  2. Batch Size: 100-1000x improvement over single inserts
  3. Indexing: 10-100x query speedup, 20% write overhead
  4. Cache Size: Diminishing returns above working set size
  5. WAL Mode: Enables concurrent reads, slight write overhead

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add benchmark scenarios or optimizations
  4. Submit pull request with performance analysis

License

MIT License - see LICENSE file for details.

Related Resources

About

An attempt to benchmarking SQLX + SQLite + Rust to validate claims for a blog post.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages