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

Memory usage with fs.createReadStream() #17

Closed
julien-f opened this issue Dec 21, 2015 · 7 comments
Closed

Memory usage with fs.createReadStream() #17

julien-f opened this issue Dec 21, 2015 · 7 comments

Comments

@julien-f
Copy link

require('trace')

var stream = require('fs').createReadStream('huge file here')
stream.resume()

It seems that the entire file is loaded in memory.

@AndreasMadsen
Copy link
Owner

There doesn't appear to be any memory leaks, but there is an odd behaviour in the RSS part which usually comes from new Buffer allocations. I have no idea what it is about, trace doesn't change the behaviour of node in any of those areas.

baseline
no-trace

with trace
with-trace

@julien-f
Copy link
Author

Side question: which tool are you using to analyse memory usage in Node?

@AndreasMadsen
Copy link
Owner

I just wrote something simple: 7e5496a

maybe I will make a real module some day :D

@AndreasMadsen
Copy link
Owner

7b91e4a should fix this. If you try it out (please do) be aware that you will need at least node version 5.2.0 for now. However I have been promised that the necessary node features will land soon in 4.x.

@AndreasMadsen
Copy link
Owner

I don't get why this is an issue. I suspect it might be a v8 bug in the gc, 7b91e4a basically just moved the stack object into an id-map and does the memory management itself. For future reference I also tried using a WeekMap, so I din't have to use the gc destroy event, there was an improvement but not enough.

WeakMap using handle object
4-weak-map

Map using uid and destructor event
5-fix

@AndreasMadsen
Copy link
Owner

Thanks for creating the issue. I really appreciate the time you use on trace and stack-chain 👍

@julien-f
Copy link
Author

Glad to help.

Thanks for your work :)

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

No branches or pull requests

2 participants