nodejs-storage: createReadStream doesn't release enough memory since version 2.2.0
Environment details
- OS: Google AppEngine (production) / macOS 10.13.6 (development)
- Node.js version: 10.15.3
- npm version: 6.9.0
@google-cloud/storage
version: 2.2.0 and up
Hi guys, I’m running into this issue when using the file.createReadStream
method. It seems this problem was introduced in version 2.2.0 and is present in all version since then (including version 2.5.0). I’m using version 2.1.0 to avoid running into this issue.
My specific use case:
- I’m streaming files that are between 100MB and 200MB in size.
- I’m using the node-throttle module.
- I’m piping the stream into the HTTP response of Express.js
bucket
.file(filename)
.createReadStream({ start, end })
.on("error", err => {
if (err.code === "ESOCKETTIMEDOUT") {
logger.warn("Error reading file stream", err);
} else {
logger.error("Error reading file stream", err);
}
})
.pipe(throttle)
.pipe(res);
Some measurements I made using the memory-usage module:
-
v2.1.0
: -
v2.2.0
: -
v2.4.0
: -
v2.5.0
:
As you can see, the version 2.1.0 graph drops memory usage, while the later versions increase linearly over time and never release the memory back, even after stopping streaming.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 34 (19 by maintainers)
I did a rewrite of the script to remove Express and the browser integration for the memory UI. I can reproduce what looks like memory retention when using master (internal request library: fetch via teeny-request), and see it disappear when using 2.1.0 (internal request library: request). Setting the range doesn’t have an effect.
I tested again with a larger file (100 MB), and memory management is different, however, neither retain beyond +5MB from the starting position.
Theories so far:
More testing needed.
Sure. Here’s the complete implementation:
You should call it with
GET http://localhost:3000/?filename={FILE_NAME}.mp3
(you need to stream an MP3 file - I use 128kbps MP3’s)I hope this helps!