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

feat: add Pebble DB backend #1069

Closed
wants to merge 11 commits into from
Closed

feat: add Pebble DB backend #1069

wants to merge 11 commits into from

Conversation

wolkykim
Copy link
Contributor

@wolkykim wolkykim commented Aug 25, 2023

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

Benchmark output, based on the random read/write test patterns we have, shows faster op time compared to the default LevelDB backend. Note that this is Async read/write)

$ go test -cpu 1,4,10 -benchmem -run=^$ -bench=. -tags pebbledb
goos: darwin
goarch: arm64
pkg: github.com/gnolang/gno/tm2/pkg/db
BenchmarkGoLevelDBRandomReadsWrites       	  313208	      4180 ns/op	     672 B/op	      13 allocs/op
BenchmarkGoLevelDBRandomReadsWrites-4     	  307611	      4138 ns/op	     680 B/op	      13 allocs/op
BenchmarkGoLevelDBRandomReadsWrites-10    	  316270	      4081 ns/op	     679 B/op	      13 allocs/op

BenchmarkPebbleDBRandomReadsWrites          	  359060	      3742 ns/op	      41 B/op	       3 allocs/op
BenchmarkPebbleDBRandomReadsWrites-4        	  376674	      3335 ns/op	      32 B/op	       3 allocs/op
BenchmarkPebbleDBRandomReadsWrites-10       	  390951	      3384 ns/op	      32 B/op	       3 allocs/op

## When PebbleDB is tuned to use 16MB cache (default 8MB)
BenchmarkPebbleDBRandomReadsWrites          	  347396	      3470 ns/op	      42 B/op	       3 allocs/op
BenchmarkPebbleDBRandomReadsWrites-4        	  368671	      3011 ns/op	      31 B/op	       3 allocs/op
BenchmarkPebbleDBRandomReadsWrites-10       	  346952	      3000 ns/op	      32 B/op	       3 allocs/op
$ go test . -tags pebbledb
ok  	github.com/gnolang/gno/tm2/pkg/db	2.151s

$ go test . -tags pebbledb -v | grep -i pebbledb
=== RUN   TestBackendsGetSetDelete/pebbledb
    --- PASS: TestBackendsGetSetDelete/pebbledb (0.06s)
=== RUN   TestBackendsNilKeys/Testing_pebbledb
    --- PASS: TestBackendsNilKeys/Testing_pebbledb (0.08s)
=== RUN   TestDBIterator/pebbledb
    --- PASS: TestDBIterator/pebbledb (0.03s)
=== RUN   TestDBIteratorSingleKey/Backend_pebbledb
    --- PASS: TestDBIteratorSingleKey/Backend_pebbledb (0.04s)
=== RUN   TestDBIteratorTwoKeys/Backend_pebbledb
    --- PASS: TestDBIteratorTwoKeys/Backend_pebbledb (0.05s)
=== RUN   TestDBIteratorMany/Backend_pebbledb
    --- PASS: TestDBIteratorMany/Backend_pebbledb (0.03s)
=== RUN   TestDBIteratorEmpty/Backend_pebbledb
    --- PASS: TestDBIteratorEmpty/Backend_pebbledb (0.04s)
=== RUN   TestDBIteratorEmptyBeginAfter/Backend_pebbledb
    --- PASS: TestDBIteratorEmptyBeginAfter/Backend_pebbledb (0.04s)
=== RUN   TestDBIteratorNonemptyBeginAfter/Backend_pebbledb
    --- PASS: TestDBIteratorNonemptyBeginAfter/Backend_pebbledb (0.04s)
=== RUN   TestPebbleDB
--- PASS: TestPebbleDB (0.04s)
=== RUN   TestPrefixIteratorNoMatchNil/Prefix_w/_backend_pebbledb
    --- PASS: TestPrefixIteratorNoMatchNil/Prefix_w/_backend_pebbledb (0.04s)
=== RUN   TestPrefixIteratorNoMatch1/Prefix_w/_backend_pebbledb
    --- PASS: TestPrefixIteratorNoMatch1/Prefix_w/_backend_pebbledb (0.05s)
=== RUN   TestPrefixIteratorNoMatch2/Prefix_w/_backend_pebbledb
    --- PASS: TestPrefixIteratorNoMatch2/Prefix_w/_backend_pebbledb (0.04s)
=== RUN   TestPrefixIteratorMatch1/Prefix_w/_backend_pebbledb
    --- PASS: TestPrefixIteratorMatch1/Prefix_w/_backend_pebbledb (0.05s)
=== RUN   TestPrefixIteratorMatches1N/Prefix_w/_backend_pebbledb
    --- PASS: TestPrefixIteratorMatches1N/Prefix_w/_backend_pebbledb (0.06s)

@wolkykim wolkykim requested review from jaekwon, moul and a team as code owners August 25, 2023 09:53
@github-actions github-actions bot added the 📦 🌐 tendermint v2 Issues or PRs tm2 related label Aug 25, 2023
@wolkykim wolkykim closed this Sep 2, 2023
@wolkykim wolkykim reopened this Sep 2, 2023
@moul
Copy link
Member

moul commented Sep 5, 2023

LGTM, could you rebase master and go mod tidy, please?

Edit: did it myself, now just looking for a second review.

Comment on lines +57 to +62
if err != nil {
if errors.Is(err, pebble.ErrNotFound) {
return nil
}
panic(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid unnecessary nesting:

Suggested change
if err != nil {
if errors.Is(err, pebble.ErrNotFound) {
return nil
}
panic(err)
}
if errors.Is(err, pebble.ErrNotFound) {
return nil
}
if err != nil {
panic(err)
}

Copy link
Contributor Author

@wolkykim wolkykim Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for most of the cases where err has nil value, the suggested logic will cost more as it goes through both L57 and L60. I honestly don't see why the suggestion is a better way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't see why the suggestion is a better way.

It is easier to read. If the code path is so hot that an extra if check will affect performance meaningfully, should we add some benchmarks to be careful about that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly, prioritizing readability and simplicity is beneficial, even in smaller cases. By consistently emphasizing clarity, we foster good habits and ensure our work remains accessible to others. It's a commendable practice to always strike a balance between efficiency and readability.

See #1111

Comment on lines +70 to +75
if err != nil {
if errors.Is(err, pebble.ErrNotFound) {
return false
}
panic(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comment here


// Implements Batch.
func (ba *pebbleDBBatch) Set(key, value []byte) {
ba.batch.Set(nonNilBytes(key), nonNilBytes(value), nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unhandled error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an error check on this.


// Implements Batch.
func (ba *pebbleDBBatch) Delete(key []byte) {
ba.batch.Delete(nonNilBytes(key), nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unhandled error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also addressed

@wolkykim
Copy link
Contributor Author

wolkykim commented Sep 6, 2023

@moul just so you know, I see you updated the go.mod file and now it builds against the latest of the pebbled's master branch. Did you intend to do so? Previously I pinned the version to use the latest crl-release-23.1 version. Anyway, there are small breaking changes in their iterator's return and I've updated the code accordingly. I think for experimental purposes it's fine not to pin it down, FYI.

@moul moul added this to the 💡Someday/Maybe milestone Sep 6, 2023
@wolkykim wolkykim closed this Sep 12, 2023
@wolkykim wolkykim deleted the pebbledb branch September 12, 2023 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related
Projects
Status: Done
Archived in project
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants