node.js - Loop of console.log in nodejs -
my mcve following
var = 0; for(;;) console.log(i++)
when this, @ moment, nodejs
stops printing stuff, giving me output looks this
[...] 684665 684666 684667
and then, got :
<--- last few gcs ---> 69097 ms: scavenge 1397.2 (1456.7) -> 1397.2 (1456.7) mb, 0.8 / 0 ms (+ 1.7 ms in 1 steps since last gc) [allocation failure] [incremental marking delaying mark-sweep]. 70462 ms: mark-sweep 1397.2 (1456.7) -> 1396.0 (1456.7) mb, 1364.9 / 0 ms (+ 2.8 ms in 2 steps since start of marking, biggest step 1.7 ms) [last resort gc]. 71833 ms: mark-sweep 1396.0 (1456.7) -> 1397.1 (1456.7) mb, 1370.2 / 0 ms [last resort gc]. <--- js stacktrace ---> ==== js stack trace ========================================= security context: 0xcdf79d37399 <js object> 1: formatprimitive(aka formatprimitive) [util.js:~411] [pc=0x634d9f4113f] (this=0xcdf79d04131 <undefined>,ctx=0x17b18f4d561 <an object map 0x32fd25043ef9>,value=16248021) 2: formatvalue(aka formatvalue) [util.js:223] [pc=0x634d9f1fdbb] (this=0xcdf79d04131 <undefined>,ctx=0x17b18f4d561 <an object map 0x32fd25043ef9>,value=16248021,recursetimes=2) 3: inspect(aka inspect) [uti... fatal error: call_and_retry_last allocation failed - process out of memory [1] 19446 abort (core dumped) node
i wondering, can console.log
lead out of memory error ?
according discussion : https://groups.google.com/forum/#!topic/nodejs/ktonbpvv68u
every time call console.log
(or other logging method), console object allocate memory. memory free garbage collector on next tick. if have big loop, next tick never come.
but tested :
setinterval(function() { (var = 0; < 100000; ++i) { console.log(i); } }, 10000)
according google group discussion, between each interval, nodejs garbage collector should free allocated memory console.log. not. every time loop running, process take more ram.
i tested :
var fs = require('fs') var output = fs.createwritestream('./stdout.log'); var erroroutput = fs.createwritestream('./stderr.log'); var logger = new console.console(output, erroroutput); var = 0; (;;) { logger.log(i++); }
the behavior same. process take more , more ram until crash (because nore more ram available). , file stdout.log
empty.
finally, tested :
var fs = require('fs') var output = fs.createwritestream('./stdout.log'); var erroroutput = fs.createwritestream('./stderr.log'); var logger = new console.console(output, erroroutput); setinterval(function() { (var = 0; < 100000; i++) { logger.log(i); } }, 5000)
this example interesting. because between each interval, stdout.log
written (the lines appended file) , ram reclaimed process doesn't grow. between each interval garbage collector works.
i think console object not handle buffer. still weird. if use standard output (with console.log
), it's console object keep in memory everthing printed far. , never cleanse. , if use file ouput, works fine (except if write in infinity loop, of course).
maybe it's because of nodejs version, i'm working nodejs 0.12.7
Comments
Post a Comment