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

use HMSET for batch Builder status store #373

Merged
merged 3 commits into from
May 5, 2023

Conversation

EliasiOfir
Copy link
Contributor

πŸ“ Summary

Moving Builders status Redis initial sync from DB to use batch requests (HMSET) and not a request per builder (HSET).
Also added tests to cover this change.

β›± Motivation and Context

following issue #204, this is one small step forward to using batch requests


βœ… I have run these commands

  • make lint
  • make test-race
  • go mod tidy
  • I have seen and agree to CONTRIBUTING.md

on initial sync from DB to Redis use HMSET instead of multiple HSET calls
datastore/redis.go Outdated Show resolved Hide resolved
@metachris
Copy link
Collaborator

That's great, thanks! Could you also apply that for writing known validators to Redis? These are 500k requests and takes a loooong time:

log.Debug("Writing to Redis...")
timeStartWriting := time.Now()
// This process can take very long, that's why it prints a log line every 10k validators
printCounter := len(hk.proposersAlreadySaved) == 0 // only do this on service startup
i := 0
newValidators := 0
for _, validator := range validators {
i++
if printCounter && i%10000 == 0 {
log.Debugf("writing to redis: %d / %d", i, numValidators)
}
// avoid resaving if index->pubkey mapping is the same
prevPubkeyForIndex := hk.proposersAlreadySaved[validator.Index]
if prevPubkeyForIndex == validator.Validator.Pubkey {
continue
}
err := hk.redis.SetKnownValidator(types.PubkeyHex(validator.Validator.Pubkey), validator.Index)
if err != nil {
log.WithError(err).WithField("pubkey", validator.Validator.Pubkey).Error("failed to set known validator in Redis")
} else {
hk.proposersAlreadySaved[validator.Index] = validator.Validator.Pubkey
newValidators++
}
}

@codecov-commenter
Copy link

codecov-commenter commented Apr 27, 2023

Codecov Report

Merging #373 (eb54c50) into main (28168e1) will increase coverage by 0.29%.
The diff coverage is 100.00%.

πŸ“£ This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main     #373      +/-   ##
==========================================
+ Coverage   19.92%   20.21%   +0.29%     
==========================================
  Files          21       21              
  Lines        4056     4062       +6     
==========================================
+ Hits          808      821      +13     
+ Misses       3145     3137       -8     
- Partials      103      104       +1     
Flag Coverage Ξ”
unittests 20.21% <100.00%> (+0.29%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Ξ”
datastore/redis.go 64.75% <100.00%> (+2.79%) ⬆️

@EliasiOfir EliasiOfir closed this Apr 27, 2023
@EliasiOfir EliasiOfir deleted the batch-set-builder-status branch April 27, 2023 13:44
@EliasiOfir EliasiOfir restored the batch-set-builder-status branch April 27, 2023 13:44
@EliasiOfir EliasiOfir reopened this Apr 27, 2023
@EliasiOfir
Copy link
Contributor Author

That's great, thanks! Could you also apply that for writing known validators to Redis? These are 500k requests and takes a loooong time:

log.Debug("Writing to Redis...")
timeStartWriting := time.Now()
// This process can take very long, that's why it prints a log line every 10k validators
printCounter := len(hk.proposersAlreadySaved) == 0 // only do this on service startup
i := 0
newValidators := 0
for _, validator := range validators {
i++
if printCounter && i%10000 == 0 {
log.Debugf("writing to redis: %d / %d", i, numValidators)
}
// avoid resaving if index->pubkey mapping is the same
prevPubkeyForIndex := hk.proposersAlreadySaved[validator.Index]
if prevPubkeyForIndex == validator.Validator.Pubkey {
continue
}
err := hk.redis.SetKnownValidator(types.PubkeyHex(validator.Validator.Pubkey), validator.Index)
if err != nil {
log.WithError(err).WithField("pubkey", validator.Validator.Pubkey).Error("failed to set known validator in Redis")
} else {
hk.proposersAlreadySaved[validator.Index] = validator.Validator.Pubkey
newValidators++
}
}

probably also need to paginate that 500,000...

@metachris
Copy link
Collaborator

Asking for a bit of patience, as we're working on other important PRs to get merged first (in particular #380)

@metachris metachris merged commit 75f6c16 into flashbots:main May 5, 2023
@metachris metachris mentioned this pull request May 23, 2023
4 tasks
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