Skip to content

Prune old log poller blocks - #7619

Merged
connorwstein merged 22 commits into
developfrom
lp-prune-old-blocks
Oct 11, 2022
Merged

Prune old log poller blocks#7619
connorwstein merged 22 commits into
developfrom
lp-prune-old-blocks

Conversation

@connorwstein

@connorwstein connorwstein commented Oct 6, 2022

Copy link
Copy Markdown
Contributor

On very fast chains, if the node stays up and has the log poller running, the performance will degrade as log_poller_blocks builds up. For example a 1s block time would produce 86400 block entries per day. This adds a periodic pruning to remove blocks more than keepBlocksDepth behind the head.

@github-actions

github-actions Bot commented Oct 6, 2022

Copy link
Copy Markdown
Contributor

I see that you haven't updated any CHANGELOG files. Would it make sense to do so?

@github-actions

github-actions Bot commented Oct 6, 2022

Copy link
Copy Markdown
Contributor

Solana Smoke Test Results

1 tests   1 ✔️  4m 38s ⏱️
1 suites  0 💤
1 files    0

Results for commit 8e9758f.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Oct 6, 2022

Copy link
Copy Markdown
Contributor

EVM Smoke Test Results

  1 files    1 suites   7m 59s ⏱️
82 tests 34 ✔️ 48 💤 0
83 runs  34 ✔️ 49 💤 0

Results for commit b65dd94.

♻️ This comment has been updated with latest results.

@connorwstein
connorwstein marked this pull request as ready for review October 7, 2022 14:32

@makramkd makramkd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM - two minor comments

// How fast that can be done depends largely on network speed and DB, but even for the fastest
// support chain, polygon, which has 2s block times, we need RPCs roughly with <= 500ms latency
func NewLogPoller(orm *ORM, ec client.Client, lggr logger.Logger, pollPeriod time.Duration, finalityDepth, backfillBatchSize, rpcBatchSize int64) *logPoller {
func NewLogPoller(orm *ORM, ec client.Client, lggr logger.Logger, pollPeriod time.Duration, finalityDepth int64, backfillBatchSize int64, rpcBatchSize int64, keepBlocksDepth int64) *logPoller {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor note/nit #1: This constructor signature is quite long, worth doing something to shorten it? We don't really have a paradigm for this in core, but just something I noticed in other places as well. In other large Go codebases I've worked on, we actually didn't have these New* methods at all and almost all fields were public (but this was also the case because we were using https://github.com/uber-go/fx).

Minor note/nit #2: this Newer returns the private *logPoller, but wouldn't it be more idiomatic if it returned the public interface type instead? (LogPoller)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

1 - I like explicit args as its just harder to misuse, you can't forget to specify a struct field this way. Lots of internal fields that I wouldn't want to expose (cached values etc.). Std go library has NewXX constructors all over it.
2 - Its more flexible to return the struct, callers can implicitly cast as needed e.g. var lp LogPoller = NewLogPoller. General go idiom is "accept interfaces, return structs"

Comment on lines +287 to +288
logPollTick := time.After(0)
blockPruneTick := time.After(0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just curiosity, but can you explain this? AFAIK go's select nondeterministically selects a branch (see https://go.dev/ref/spec#Select_statements):

If one or more of the communications can proceed, a single one that can proceed is chosen via a uniform pseudo-random selection.

What's the benefit of doing this vs. setting them to the appropriate durations straight away here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it is indeed random - no real benefit imo. I didn't see much of a difference between pruning or begin polling on lp boot

makramkd
makramkd previously approved these changes Oct 11, 2022

@makramkd makramkd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:shipit:

@connorwstein
connorwstein merged commit e3600f9 into develop Oct 11, 2022
@connorwstein
connorwstein deleted the lp-prune-old-blocks branch October 11, 2022 15:04
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.

2 participants