Skip to content

Commit 8e556e1

Browse files
committed
Add database persistence benchmarks
Benchmark realistic payment and pending-payment persistence workloads across filesystem, SQLite, and optional PostgreSQL stores. Use the async KV-store APIs so the measured paths match the database interfaces used by async persistence. AI-Assisted: Codex
1 parent 670630d commit 8e556e1

5 files changed

Lines changed: 1146 additions & 1 deletion

File tree

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ jobs:
4545
echo "ELECTRS_EXE=$( pwd )/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
4646
- name: Run benchmarks
4747
run: |
48-
RUSTFLAGS="--cfg tokio_unstable" cargo bench
48+
RUSTFLAGS="--cfg tokio_unstable" cargo test --benches --features bench

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ panic = 'abort' # Abort on panic
2525

2626
[features]
2727
default = []
28+
bench = []
2829
postgres = ["dep:tokio-postgres", "dep:native-tls", "dep:postgres-native-tls"]
2930

3031
[dependencies]
@@ -142,6 +143,11 @@ check-cfg = [
142143
name = "payments"
143144
harness = false
144145

146+
[[bench]]
147+
name = "database"
148+
harness = false
149+
required-features = ["bench"]
150+
145151
#[patch.crates-io]
146152
#lightning = { path = "../rust-lightning/lightning" }
147153
#lightning-types = { path = "../rust-lightning/lightning-types" }

benches/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)