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 pebbledb #112

Merged
merged 23 commits into from
Jan 24, 2024
Merged

feat: add pebbledb #112

merged 23 commits into from
Jan 24, 2024

Conversation

faddat
Copy link
Contributor

@faddat faddat commented Jan 7, 2024

This is a basic PR adding pebbledb.

Its license remains unchanged, apache 2.

Closes #90

@faddat faddat requested a review from a team as a code owner January 7, 2024 09:25
Copy link

codecov bot commented Jan 7, 2024

Codecov Report

Attention: 69 lines in your changes are missing coverage. Please review.

Comparison is base (f7a229f) 77.53% compared to head (4616932) 77.15%.

❗ Current head 4616932 differs from pull request most recent head d74f5de. Consider uploading reports for the commit d74f5de to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #112      +/-   ##
==========================================
- Coverage   77.53%   77.15%   -0.39%     
==========================================
  Files          22       23       +1     
  Lines        1785     2057     +272     
==========================================
+ Hits         1384     1587     +203     
- Misses        342      399      +57     
- Partials       59       71      +12     
Files Coverage Δ
db.go 35.00% <ø> (ø)
pebble.go 74.63% <74.63%> (ø)
Files Coverage Δ
db.go 35.00% <ø> (ø)
pebble.go 74.63% <74.63%> (ø)

@faddat faddat mentioned this pull request Jan 7, 2024
@faddat faddat closed this Jan 7, 2024
@faddat faddat reopened this Jan 9, 2024
@faddat
Copy link
Contributor Author

faddat commented Jan 9, 2024

Here's why:

goos: darwin
goarch: arm64
pkg: github.com/cometbft/cometbft-db
BenchmarkGoLevelDBRandomReadsWrites-12    	  341013	      3626 ns/op
BenchmarkMemDBRangeScans1M-12             	    1035	   1120334 ns/op
BenchmarkMemDBRangeScans10M-12            	    1024	   1153464 ns/op
BenchmarkMemDBRandomReadsWrites-12        	 1000000	      1900 ns/op
BenchmarkDB/Keys_1000e3_Values_1024_pebbledb-12         	1000000000	         0.01967 ns/op
BenchmarkDB/Keys_1000e3_Values_1024_goleveldb-12        	1000000000	         0.008117 ns/op
BenchmarkDB/Keys_1000e3_Values_2048_pebbledb-12         	1000000000	         0.02024 ns/op
BenchmarkDB/Keys_1000e3_Values_2048_goleveldb-12        	1000000000	         0.01085 ns/op
BenchmarkDB/Keys_1000e3_Values_4096_pebbledb-12         	1000000000	         0.02399 ns/op
BenchmarkDB/Keys_1000e3_Values_4096_goleveldb-12        	1000000000	         0.02797 ns/op
BenchmarkDB/Keys_1000e3_Values_8192_pebbledb-12         	1000000000	         0.02593 ns/op
BenchmarkDB/Keys_1000e3_Values_8192_goleveldb-12        	1000000000	         0.04745 ns/op
BenchmarkDB/Keys_1000e3_Values_16384_pebbledb-12        	1000000000	         0.02701 ns/op
BenchmarkDB/Keys_1000e3_Values_16384_goleveldb-12       	1000000000	         0.1009 ns/op
BenchmarkDB/Keys_1000e3_Values_32768_pebbledb-12        	1000000000	         0.03281 ns/op
BenchmarkDB/Keys_1000e3_Values_32768_goleveldb-12       	1000000000	         0.1990 ns/op
BenchmarkDB/Keys_10000e3_Values_1024_pebbledb-12        	1000000000	         0.06059 ns/op
BenchmarkDB/Keys_10000e3_Values_1024_goleveldb-12       	1000000000	         0.1255 ns/op
BenchmarkDB/Keys_10000e3_Values_2048_pebbledb-12        	1000000000	         0.06427 ns/op
BenchmarkDB/Keys_10000e3_Values_2048_goleveldb-12       	1000000000	         0.1891 ns/op
BenchmarkDB/Keys_10000e3_Values_4096_pebbledb-12        	1000000000	         0.07321 ns/op
BenchmarkDB/Keys_10000e3_Values_4096_goleveldb-12       	1000000000	         0.3783 ns/op
BenchmarkDB/Keys_10000e3_Values_8192_pebbledb-12        	1000000000	         0.09354 ns/op
BenchmarkDB/Keys_10000e3_Values_8192_goleveldb-12       	
1000000000	         0.7913 ns/op
BenchmarkDB/Keys_10000e3_Values_16384_pebbledb-12       	1000000000	         0.1290 ns/op
BenchmarkDB/Keys_10000e3_Values_16384_goleveldb-12      	       1	1625503416 ns/op
BenchmarkDB/Keys_10000e3_Values_32768_pebbledb-12       	1000000000	         0.1941 ns/op
BenchmarkDB/Keys_10000e3_Values_32768_goleveldb-12      	       1	4447018291 ns/op

@faddat
Copy link
Contributor Author

faddat commented Jan 14, 2024

In order to write good benchmarks we need to merge this.

@faddat
Copy link
Contributor Author

faddat commented Jan 15, 2024

FYI, this one JUST AND ONLY adds pebble.

@adizere adizere linked an issue Jan 19, 2024 that may be closed by this pull request
@adizere adizere added this to the 2024-Q1 milestone Jan 19, 2024
@adizere adizere removed this from the 2024-Q1 milestone Jan 19, 2024
@jmalicevic
Copy link
Contributor

So it seems that golevelDB is only more performant when we have small keys and write fewer of them (the first few lines). I am wondering what would the numbers look like for 64KB requests (which is the default block part size in Comet) , so it would be great to benchmark that.
In any case, lets work on merging this PR so there is support for PebbleDB.

pebble.go Outdated Show resolved Hide resolved
pebble.go Outdated Show resolved Hide resolved
pebble.go Outdated Show resolved Hide resolved
pebble.go Outdated Show resolved Hide resolved
pebble.go Outdated Show resolved Hide resolved
pebble.go Outdated Show resolved Hide resolved
pebble_test.go Show resolved Hide resolved
pebble.go Outdated Show resolved Hide resolved
pebble.go Show resolved Hide resolved
pebble.go Outdated
This is set at compile time. Could be 0 or 1, defaults is 0.
It will force using Sync for NoSync functions (Set, Delete, Write)

Used as a workaround for chain-upgrade issue: At the upgrade-block, the sdk will panic without flushing data to disk or
Copy link
Contributor

Choose a reason for hiding this comment

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

How was this handled with existing databases where we did not introduce this ForceSync flag?

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 think that it may make more sense to go through #115 -- it uses pebbledb 1.0 and doesn't seem to need this, but @baabeetaa can provide more context I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

i havent tried newer version of pebbledb. With current version, set it default to 1 instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

btw, i'll test upgrading without ForceSync=1 with new version of pebbledb tomorrow and report.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice -- could you test the #115 branch?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, there will be Omniflix mainnet upgrade tomorrow.

Copy link
Contributor

Choose a reason for hiding this comment

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

i tried upgrading Omniflix with pebble v1.0.0. It doesnt work without using ForceSync

Copy link
Contributor

Choose a reason for hiding this comment

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

Imo, using default ForceSync=1 shoulnt be a problem.
https://github.com/cockroachdb/pebble/blob/master/options.go#L356

Copy link
Contributor

Choose a reason for hiding this comment

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

i updated default ForceSync=1, so no need to use this flag when upgrading.

faddat and others added 6 commits January 20, 2024 01:30
Co-authored-by: Jasmina Malicevic <jasmina.dustinac@gmail.com>
Co-authored-by: Jasmina Malicevic <jasmina.dustinac@gmail.com>
Co-authored-by: Jasmina Malicevic <jasmina.dustinac@gmail.com>
Co-authored-by: Jasmina Malicevic <jasmina.dustinac@gmail.com>
Co-authored-by: Jasmina Malicevic <jasmina.dustinac@gmail.com>
Co-authored-by: Jasmina Malicevic <jasmina.dustinac@gmail.com>
@faddat faddat marked this pull request as draft January 21, 2024 21:38
@faddat
Copy link
Contributor Author

faddat commented Jan 21, 2024

I think that #115 is overall better and is better for review. This PR is a cherry pick of @baabeetaa 's 2 year old work, and is missing things like the stats method, which are in #115

#115 also uses a more recent pebbledb.

@adizere
Copy link
Member

adizere commented Jan 23, 2024

Should we just keep #115 and close this then? Or is there anything specific in this PR that is valuable?

@jmalicevic
Copy link
Contributor

Should we just keep #115 and close this then? Or is there anything specific in this PR that is valuable?

I don't have any objections, the reason I went over this one is that it was clean and only changing Pebble. I would like to avoid changing existing behaviour of pre-existing DBs in #115 but otherwise no objections to closing this in favor of #115.

@baabeetaa
Copy link
Contributor

I run iavl bench Large for:

the differences are several percentages.

So could set ForceSync=1 as default to avoid the upgrading issue without hurting performance much.

@melekes melekes changed the title add pebbledb (again) feat: add pebbledb Jan 24, 2024
Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

Thanks @baabeetaa and @faddat ❤️

db.go Outdated Show resolved Hide resolved

Notice if ForceSync=0: performance will be better. However, there is an issue when upgrading.
And the workaround (if using ForceSync=0):
At the upgrade-block, the sdk will panic without flushing data to disk or closing dbs properly.
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't get it. Isn't the solution to use SetSync in the SDK? instead of forcing all ops to be sync

Copy link
Contributor

Choose a reason for hiding this comment

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

i agree. However, this isnt an issue with goleveldb which is the default db. And other dbs are experiments atm.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it not degrade performance if done needlessly?

Copy link
Contributor

@melekes melekes Jan 24, 2024

Choose a reason for hiding this comment

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

Still, the right way is to patch Cosmos SDK, not leave this hack even though pebbledb is experimental. Please remove

Copy link
Contributor

Choose a reason for hiding this comment

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

Sir, it could be a big problem for node operators who run nodes for different chains and different sdk versions.
Also when syching archive nodes from genesis requires a lot of upgrades.
This hack is not the best way to fix. But it works.

Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
@melekes melekes added this pull request to the merge queue Jan 24, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Jan 24, 2024
@melekes
Copy link
Contributor

melekes commented Jan 24, 2024

@baabeetaa or @faddat - could you please resolve conflicts?

@melekes
Copy link
Contributor

melekes commented Jan 24, 2024

This PR also lacks a changelog entry. Please add one ☝️

@melekes
Copy link
Contributor

melekes commented Jan 24, 2024

Changelog entry must be added in .changelog (we use unclog to manage our changelog)

CHANGELOG.md Outdated Show resolved Hide resolved
renamed 112-add-pebbledb.md to 112-pebbledb.md
@melekes melekes added this pull request to the merge queue Jan 24, 2024
Merged via the queue into cometbft:main with commit 2af169e Jan 24, 2024
6 checks passed
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.

Add support for pebbleDB
5 participants