Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Fix OutOfMemory in read stream #38

Merged
merged 2 commits into from
Mar 13, 2018
Merged

Fix OutOfMemory in read stream #38

merged 2 commits into from
Mar 13, 2018

Conversation

medvedev1088
Copy link
Contributor

@medvedev1088 medvedev1088 commented Mar 7, 2018

Fix for #36

The root cause of the issue is the trie is traversed asynchronously, in such a way that nodes on different levels are explored with equal probability, resembling breadth-first search. This requires the bulk of the trie to be loaded into memory before any entries can be emitted by the stream.

This pull request adds PrioritizedTaskExecutor with a pool and a priority queue, node lookups are prioritised by node key length. This resembles depth-first search, which solves the issue.

New code is covered in test/prioritizedTaskExecutor.js

Also tested here https://github.com/medvedev1088/merkle-patricia-tree/pull/1

@medvedev1088 medvedev1088 changed the title Fix Out Of Memory for read stream Fix OutOfMemory for read stream Mar 7, 2018
@coveralls
Copy link

coveralls commented Mar 7, 2018

Coverage Status

Coverage decreased (-0.01%) to 81.135% when pulling 6731209 on medvedev1088:bug/36-read-stream-oom into f627d76 on ethereumjs:master.

@medvedev1088 medvedev1088 changed the title Fix OutOfMemory for read stream Fix OutOfMemory in read stream Mar 8, 2018
@holgerd77 holgerd77 self-requested a review March 9, 2018 08:57
@holgerd77 holgerd77 self-assigned this Mar 9, 2018
@holgerd77
Copy link
Member

Hi, great, thanks for this extensive PR! 😺

I will try to have a look into this next week, currently at EthCC (if you are as well we can also meet).

Can you rebase and squash the first 7 commits (be7ae to eece4) into the first (be7ae) commit, and also squash together the last two commits, these are mostly back-and-forth commits and bloat the commit history (if you haven't use rebase functionality before you should do a local copy of your repository directory since things can go wrong).

@holgerd77
Copy link
Member

holgerd77 commented Mar 9, 2018

Process would be: update your master branch with the latest master changes, go to your branch and do git rebase -i master.

(if there are any master changes, not sure).

@medvedev1088
Copy link
Contributor Author

@holgerd77 Done!

Unfortunately, I'm not at EthCC.

@holgerd77
Copy link
Member

Beautiful. 👍

Otherwise this is ready for review?

@medvedev1088
Copy link
Contributor Author

Yep, ready :)

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Ok, I now managed to get the example from @ivica7 running on my local geth database. Also had a look at the code line-by-line and for understanding what it does.

Since all the tests are also passing, I think I can give this a go now.

Really beautiful PR, thanks again! 🌻 😄

@holgerd77 holgerd77 merged commit c1b17e0 into ethereumjs:master Mar 13, 2018
@medvedev1088 medvedev1088 deleted the bug/36-read-stream-oom branch March 14, 2018 07:25
@holgerd77
Copy link
Member

Just did the associated release on npm: https://github.com/ethereumjs/merkle-patricia-tree/releases/tag/v2.3.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants