Skip to content

Commit f5043af

Browse files
dcadenasyukibtc
authored andcommitted
lmdb: implement automatic event batching with flume channels
Update the LMDB ingester to support automatic event batching for improved write performance. The existing ingester has been enhanced to process multiple operations in batches using single LMDB transactions, significantly reducing write overhead. Key changes: - Modify ingester to process events in batches rather than one-by-one, using a single RwTxn per batch; - Add support for delete operations alongside save operations in the ingester. Pull-Request: #1010 Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent eadccd1 commit f5043af

File tree

6 files changed

+486
-75
lines changed

6 files changed

+486
-75
lines changed

Cargo.lock

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

database/nostr-lmdb/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
### Changed
2929

3030
- Consolidate deletion logic and improve transactional consistency (https://github.com/rust-nostr/nostr/pull/1010)
31+
- Add automatic event batching for better write performance (https://github.com/rust-nostr/nostr/pull/1010)
3132

3233
## v0.43.0 - 2025/07/28
3334

database/nostr-lmdb/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ keywords = ["nostr", "database", "lmdb"]
1313

1414
[dependencies]
1515
async-utility.workspace = true
16+
flume = "0.11"
1617
nostr = { workspace = true, features = ["std"] }
1718
nostr-database = { workspace = true, features = ["flatbuf"] }
1819
tokio = { workspace = true, features = ["sync"] }
@@ -26,5 +27,6 @@ heed = { version = "0.20", default-features = false, features = ["read-txn-no-tl
2627
heed = { version = "0.20", default-features = false, features = ["read-txn-no-tls", "posix-sem"] }
2728

2829
[dev-dependencies]
30+
futures = "0.3"
2931
tempfile.workspace = true
3032
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

database/nostr-lmdb/src/store/error.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ pub enum Error {
2222
Key(key::Error),
2323
Secp256k1(secp256k1::Error),
2424
OneshotRecv(oneshot::error::RecvError),
25-
/// MPSC send error
26-
MpscSend,
25+
/// Flume channel send error
26+
FlumeSend,
2727
/// The event kind is wrong
2828
WrongEventKind,
2929
/// Not found
3030
NotFound,
31+
/// Batched transaction failed - sent to operations that didn't cause the error
32+
BatchTransactionFailed,
3133
}
3234

3335
impl std::error::Error for Error {}
@@ -42,9 +44,10 @@ impl fmt::Display for Error {
4244
Self::Key(e) => write!(f, "{e}"),
4345
Self::Secp256k1(e) => write!(f, "{e}"),
4446
Self::OneshotRecv(e) => write!(f, "{e}"),
45-
Self::MpscSend => write!(f, "mpsc channel send error"),
47+
Self::FlumeSend => write!(f, "flume channel send error"),
4648
Self::NotFound => write!(f, "Not found"),
4749
Self::WrongEventKind => write!(f, "Wrong event kind"),
50+
Self::BatchTransactionFailed => write!(f, "Batched transaction failed"),
4851
}
4952
}
5053
}

0 commit comments

Comments
 (0)