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

[actpool] impl a store to cache actions on disk #4362

Merged
merged 8 commits into from
Aug 20, 2024

Conversation

envestcc
Copy link
Member

@envestcc envestcc commented Aug 13, 2024

Description

blobstore is a customized, high-performance datastore for transient actions, which is backed by billy (a super simple datastore, also the blobpool storage option chosen by Ethereum). It will be used for cache actions so that can load from local when restart, avoiding large load on the network.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

r.Equal(act, acts[0])
}

func BenchmarkDatabase(b *testing.B) {
Copy link
Member Author

@envestcc envestcc Aug 14, 2024

Choose a reason for hiding this comment

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

benchmark: around 60x faster than kv

goos: darwin
goarch: arm64
pkg: github.com/iotexproject/iotex-core/actpool
BenchmarkDatabase/billy-put-10             10000            138064 ns/op          140654 B/op          1 allocs/op
BenchmarkDatabase/pebbledb-put-10            158           6843763 ns/op           24024 B/op         27 allocs/op
BenchmarkDatabase/boltdb-put-10              120           8863447 ns/op          541060 B/op         64 allocs/op
PASS
ok      github.com/iotexproject/iotex-core/actpool      5.885s

@envestcc envestcc changed the title [actpool] impl a blobstore to cache blobs on disk [actpool] impl a store to cache actions on disk Aug 15, 2024
actpool/blobstore.go Outdated Show resolved Hide resolved
actpool/blobstore.go Outdated Show resolved Hide resolved
}

func (s *blobStore) drop() {
for {
Copy link
Member

Choose a reason for hiding this comment

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

just lock the s.lookup map, and delete all items?

Copy link
Member Author

Choose a reason for hiding this comment

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

lock/unlock should be called only in public methods

Copy link
Member

Choose a reason for hiding this comment

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

then define a public method? the current implementation is actually not correct, access to s.lookup should be protected with a lock (just like in other funcs) right?

Copy link
Member Author

Choose a reason for hiding this comment

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

drop() is called by Put(), should not be called by outside

Copy link
Member

Choose a reason for hiding this comment

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

OK I see, add a TODO or file an issue for a better drop policy, for now it is simply deleting all items, the newly added item could also be deleted

Copy link
Member

Choose a reason for hiding this comment

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

as discuss, no need for, just delete the first item returned from evict

func (s *blobStore) Get(hash hash.Hash256) (*action.SealedEnvelope, error) {
s.lock.RLock()
defer s.lock.RUnlock()
if s.store == nil {
Copy link
Member

Choose a reason for hiding this comment

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

add a Readiness to s, and use s.IsReady()

Copy link

codecov bot commented Aug 19, 2024

Codecov Report

Attention: Patch coverage is 40.17857% with 67 lines in your changes missing coverage. Please review.

Project coverage is 75.65%. Comparing base (36f0d99) to head (c7c461d).
Report is 6 commits behind head on master.

Files Patch % Lines
actpool/blobstore.go 40.17% 60 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4362      +/-   ##
==========================================
- Coverage   75.86%   75.65%   -0.21%     
==========================================
  Files         361      364       +3     
  Lines       30116    30407     +291     
==========================================
+ Hits        22846    23005     +159     
- Misses       6134     6246     +112     
- Partials     1136     1156      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


// TODO: implement a proper eviction policy
func (s *blobStore) evict() (hash.Hash256, bool) {
for h := range s.lookup {
Copy link
Member

Choose a reason for hiding this comment

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

add a TODO, to find the worst action according to some policy

Copy link

sonarcloud bot commented Aug 19, 2024

@envestcc envestcc merged commit 87a240b into iotexproject:master Aug 20, 2024
3 checks passed
@envestcc envestcc deleted the actpool_disk branch August 20, 2024 01:53
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