-
-
Save inimino/374051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bash one-liner to run it and watch memory usage | |
( ./node test.js & PID=$! && trap 'kill $PID' 0; while sleep 1; do ps -o rss= -p $PID; done ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys') | |
function processAll (items, callback) { | |
next() | |
function next(){ | |
if(!items.length) callback() | |
else processOne(items.pop(), cb)} | |
function cb(){ | |
if(items.length%1000 == 0) sys.puts('Remaining: '+items.length) | |
if(items.length%10000 == 0) setTimeout(next, 10000) // wait for gc to happen | |
else next()}} | |
function processOne (item, callback) { | |
// Simulate some work | |
setTimeout(callback, 2) | |
} | |
var items = [] | |
for (i = 0; i < 400000; i++) | |
items.push(i) | |
processAll(items, function() { | |
sys.puts("done") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment