eth,core: re-enable LRU cache in GetLogs #25425
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE: IMO this PR is not yet ready for merge, it's more of a starting off point.
As noted in #25421 I'm pretty sure there's a rather severe performance regression around the
eth_getLogs
RPC.To validate that, I've made this PR which re-enables the
BlockChain
codepath to reintroduce thereceiptsCache
LRU into the mix.On two mainnet nodes each receiving a rather high volume of
eth_getLogs
RPCs (but only for the most recent 128 blocks) the pprof flamegraph is rather telling.Note that in both cases I'm already running with a small patch that raises the size of the receiptsCache LRU from
32
to1024
, available here: ryanschneider@ae9a5eeAnyways, with only that patch applied, we see that overall a lot of time is spent in
unindexedLogs
, and that most of that time is spent inReadLogs
:Note that this flame graph is a 30s CPU profile, so at 188s of CPU time
unindexedLogs
is fully consuming more than 6 CPUs at 100% utilization.And now with the work-in-progress patch in this PR:
Of course we don't see
ReadLogs
at all any more, since that code isn't in the codepath anymore, but note that overall CPU time ofunindexedLogs
is now only 3.7s.Why I consider this PR is still Work-In-Progess
There's two main reasons I'd consider this PR a WIP:
ReadLogs
entirely since it's not used.It's definitely possible to get the "best of both worlds" by adding a LRU cache to
ReadLogs
but I don't currently see anything like that inrawdb
and I wouldn't want to introduce something like that w/o discussing it first. Note that doing so would also add more memory usage as this LRU would be specialized to logs and not receipts and thus could not be reused so would "compete" w/ the existing LRUs inBlockChain
.Basically the balancing act is that the current master version has somewhat better overall performance for single RPCs by avoiding some redundant decoding in the rawdb layer, but has overall worse parallel performance due to the lack of caching leading to the same receipts/logs being read from the DB multiple times.
Anyways cc @s1na @fjl and @holiman since you three have been involved in ✅ for all recent PRs on this subject.