Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimental redb database backend support #1045

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

antonilol
Copy link
Contributor

depends on #1043 because fixed size datatypes made this pr easier

a bit inspired by #765, only not trying to get a dozen DBs to work at once, and not using any dynamic dispatch

still experimental because it performed a bit worse than rocksdb in my initial try (indexing on the signet), but that could be due to other factors as well (both were running from the same bitcoind so one might have gotten prioritized maybe?)

there is a few TODOs still (like metrics from the db) and probably some configuration still needed to get more speed out of the hardware

the Database trait defines all things the rest of electrs can do with a database backend, so more databases can be added later, even a built in in-memory db maybe for automated testing or just quick regtest setup

@antonilol
Copy link
Contributor Author

redb needs at least rustc 1.66, and the Database trait in the pr uses generic associated types which were stabilized in 1.65 (redb also uses them)
1.66 is almost 1 and a half year old and debian stable still has 1.63

@yancyribbens
Copy link

why not sled?

@antonilol
Copy link
Contributor Author

stats so far:
db size on signet (block height 197272), rocksdb: 152M, redb: 447M (rocksdb uses compression, right?)
indexing time, rocksdb: 1 minute, redb: 6 minutes on ssd
on hdd rocksdb takes about the same time and appears to commit only 3 times, while redb commits way more often and was really slow

clearly I am doing something wrong here because redb's performance is comparable to that of rocksdb according to the project maintainer's benchmarks

could signet just be the wrong thing to test with? will redb perform better (compared to rocksdb) once rocksdb can't do (almost) everything in ram?

@antonilol
Copy link
Contributor Author

why not sled?

I initially considered starting with redb or sled, both are in beta, but I chose redb because its file format is stable, contrary to sled which has warnings about possible manual migration in its readme

I will try sled right now, hopefully I get it to work with similar performance compared to rocksdb

@yancyribbens
Copy link

fwiw sled claims to be in alpha now

@antonilol
Copy link
Contributor Author

fwiw sled claims to be in alpha now

they name beta in their readme, anyway this should only be an issue if there are bugs in there, and the manual migrations only become an issue when updating sled in the future, if they put a breaking change in a patch version (semver people wont be happy then) we just pin it to a previous (working) patch version

@antonilol
Copy link
Contributor Author

good news for sled: its minimum rust version is below that of electrs (redb would require a higher one) and I can work around not being able to use generic associated types, there is a workaround for that for old versions of rust
(if I get it working I will revert the change to rust-toolchain.toml, it's set higher now for redb)

@Kixunil
Copy link
Contributor

Kixunil commented Jun 19, 2024

I hope we don't end up with sled. Manual migration would be very annoying for the users.

@antonilol
Copy link
Contributor Author

It shouldn't be annoying for electrs users, there is a bit of doc from sled on how to do migration, (import and export functions), in electrs we can make this an automatic migration. I think "manual" refers to users of sled (rust projects that use it as library, like electrs) need to manually add/change code for some updates.

@Kixunil
Copy link
Contributor

Kixunil commented Jun 22, 2024

Still no migration is better than migration which takes time and resources.

@antonilol antonilol force-pushed the redb branch 3 times, most recently from 6bbf852 to b1cfafc Compare July 13, 2024 15:32
for the time being i updated the used rust toolchain to 1.65 because
generic associated types were needed
for now set as default features
set rust version to 1.66 bacuse redb requires that
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants