|
| 1 | +# Benchmarks |
| 2 | + |
| 3 | +This directory holds [Criterion](https://docs.rs/criterion) benchmarks for LDK Node. There are |
| 4 | +three benchmark targets: |
| 5 | + |
| 6 | +| Target | What it measures | |
| 7 | +|--------|------------------| |
| 8 | +| `database` | Low-level `KVStore` operations (single read/write/remove, batched & concurrent writes, paginated listing, payment reload) across the filesystem, SQLite and PostgreSQL backends. | |
| 9 | +| `operations` | Higher-level node operations: payment forwarding, channel opens, and node startup time seeded with varying channel/payment history. | |
| 10 | +| `payments` | End-to-end payment throughput between two nodes across store backends. | |
| 11 | + |
| 12 | +The `operations` and `payments` benchmarks spin up real `bitcoind`/`electrs` instances and full |
| 13 | +nodes, so they take a while to run. The `database` benchmark only exercises the storage layer and |
| 14 | +is comparatively quick. |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | + |
| 18 | +- `bitcoind` and `electrs` binaries for the `operations` and `payments` benchmarks. Point the |
| 19 | + `BITCOIND_EXE` and `ELECTRS_EXE` environment variables at them (see |
| 20 | + `scripts/download_bitcoind_electrs.sh` for a convenient way to fetch them). |
| 21 | +- The `bench` feature is required for the `database` benchmark. |
| 22 | +- The `postgres` feature plus a reachable PostgreSQL server (set `TEST_POSTGRES_URL`) are required |
| 23 | + to include the PostgreSQL backend. Without it, the filesystem and SQLite backends still run. |
| 24 | + |
| 25 | +## Running |
| 26 | + |
| 27 | +Run everything for real measurements: |
| 28 | + |
| 29 | +```sh |
| 30 | +RUSTFLAGS="--cfg tokio_unstable" cargo bench --benches --features bench |
| 31 | +``` |
| 32 | + |
| 33 | +`--cfg tokio_unstable` is optional; it enables the tokio eager driver handoff used by the benchmark |
| 34 | +runtimes. Without it the benchmarks still run. |
| 35 | + |
| 36 | +Run a single target: |
| 37 | + |
| 38 | +```sh |
| 39 | +cargo bench --bench database --features bench |
| 40 | +cargo bench --bench operations |
| 41 | +cargo bench --bench payments |
| 42 | +``` |
| 43 | + |
| 44 | +Filter to specific cases (Criterion takes a substring filter; the `operations` target also uses it |
| 45 | +to skip expensive setup for cases that don't match): |
| 46 | + |
| 47 | +```sh |
| 48 | +cargo bench --bench operations -- channel_open |
| 49 | +cargo bench --bench database --features bench -- sqlite |
| 50 | +``` |
| 51 | + |
| 52 | +### PostgreSQL backend |
| 53 | + |
| 54 | +```sh |
| 55 | +export TEST_POSTGRES_URL="host=localhost user=postgres password=postgres" |
| 56 | +cargo bench --benches --features "bench postgres" |
| 57 | +``` |
| 58 | + |
| 59 | +Benchmark fixtures create their tables in the `ldk_db` database (the default used when the |
| 60 | +connection string omits a `dbname`) and drop them on teardown. |
| 61 | + |
| 62 | +## CI |
| 63 | + |
| 64 | +The `benchmarks` workflow smoke-runs the benchmarks with `cargo test --benches --features bench` (a |
| 65 | +single iteration each) to keep them compiling and working rather than collecting full measurements. |
| 66 | +It does not require PostgreSQL; PostgreSQL coverage is opt-in for local runs by enabling the |
| 67 | +`postgres` feature and setting `TEST_POSTGRES_URL`. The seeded `startup` scenarios in `operations` |
| 68 | +detect CI via the `CI` environment variable and only run the smallest scenario there; the full set |
| 69 | +runs locally. |
0 commit comments