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

receipt cache limited by volumes #103

Closed

Conversation

bendanzhentan
Copy link
Contributor

@bendanzhentan bendanzhentan commented Dec 25, 2023

The receipts cache was originally a LRUCache type that was limited by the number of elements, but there is a problem, meaning that if the recent block contains too many receipts, then the receipts cache can take up a lot of memory. To limit the memory usage of the receipts cache, this PR changes the cache type to SizeConstrainedCache, which is limited by the total volume of elements.

@bendanzhentan bendanzhentan force-pushed the cache-max-volumn branch 2 times, most recently from 630cc4c to a5d2767 Compare December 25, 2023 08:59
type SizeConstrainedCache[K comparable, V any] struct {
m Metrics
label string
size int
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps uint64 type should be used instead, it is uncertain if int type will overflow when counting byte size.

} else {
txHashes := eth.TransactionsToHashes(txs)
job = NewReceiptsFetchingJob(s, s.client, s.maxBatchSize, eth.ToBlockID(info), info.ReceiptHash(), txHashes)
_, err := job.Fetch(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to execute Fetch here, please refer to the comments above. The reason for caching the job instead of the receipts is that it saves the intermediate state, so even if it fails, it can continue to execute the next time.

@bendanzhentan bendanzhentan force-pushed the cache-max-volumn branch 2 times, most recently from 49a8c69 to 352ccb6 Compare December 25, 2023 09:51
@bendanzhentan bendanzhentan changed the title receitp cache limited by volumes receipt cache limited by volumes Dec 26, 2023
@owen-reorg
Copy link
Collaborator

Two concerns:

  1. The size used is not very accurate.
  2. It introduces overhead when adding cache items.

I'm not sure if it's worth it.

@owen-reorg
Copy link
Collaborator

Using higher memory should be good enough for now, we'll close this PR.

@owen-reorg owen-reorg closed this Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants