Garbage collector doesn't seem to run whenever stdout is piped #4977
Unanswered
Trinovantes
asked this question in
Q&A
Replies: 0 comments 5 replies
-
You can move it to issue section. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I was able to resolve this by manually releasing the event loop (at a slight performance hit) async function fizzbuzz() {
let buffer = ''
for (let i = 0n; i < MAX; i += 15n) {
buffer += `${i + 1n}\n${i + 2n}\nFizz\n${i + 4n}\nBuzz\nFizz\n${i + 7n}\n${i + 8n}\nFizz\nBuzz\n${i + 11n}\nFizz\n${i + 13n}\n${i + 14n}\nFizzBuzz\n`
if (buffer.length > BUFFER_SIZE) {
process.stdout.write(buffer)
buffer = ''
await new Promise((resolve) => setTimeout(resolve, 0))
}
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been playing around to see how fast nodejs' throughput is but I noticed that my program constantly crashes with OOM errors only when I'm piping my stdout to another program rather than a file
If I try to run this program with
node main.js | pv > /dev/null
, the memory usage stays fine for a few seconds before it quickly spikes to the 4 GB heap limit and crashes.However if I try to run this program with
node main.js > /dev/null
ornode main.js > tmp.txt
, it runs just fine and memory usage stays constant.I've tested on both v16.15.0 and v18.4.0.
Beta Was this translation helpful? Give feedback.
All reactions