Created
March 23, 2012 20:38
-
-
Save anton-ryzhov/2174719 to your computer and use it in GitHub Desktop.
node.js async test
This file contains hidden or 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
Files: | |
mkfifo pipe pipe2 | |
pv -L 3M /dev/zero > pipe | |
pv -L 3M /dev/zero > pipe2 | |
ps -AL | grep node | |
Socket: | |
pv -L 1M /dev/zero | nc -l 1234 |
This file contains hidden or 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 lastcall, done, | |
fs = require('fs'); | |
function showDate(s) | |
{ | |
var now = new Date() - 0; | |
lastcall = lastcall ? lastcall : now; | |
console.log(s + ': ' + new Date() + ', ' + ' +' + (now - lastcall) + ' ' + (process.memoryUsage().rss/1024/1024) + ' Mb' + '\n'); | |
lastcall = now; | |
} | |
function sleep(n) | |
{ | |
var goal = new Date() - 0 + n*1000; | |
while ((new Date() - 0) < goal); | |
} | |
showDate('start'); | |
done = 0; | |
fs.readFile('pipe', function (err, data) { | |
showDate('end read'); | |
console.log('filelen ' + data.length + '\n'); | |
done = 1; | |
}); | |
fs.readFile('pipe2', function (err, data) { | |
showDate('end read2'); | |
console.log('filelen ' + data.length + '\n'); | |
done = 1; | |
}); | |
showDate('start read'); | |
function echo() | |
{ | |
console.log(new Date() - 0); | |
if (!done) | |
setTimeout(echo, 500); | |
} | |
setTimeout(echo, 0); |
This file contains hidden or 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 lastcall, done, | |
net = require('net'); | |
function showDate(s) | |
{ | |
var now = new Date() - 0; | |
lastcall = lastcall ? lastcall : now; | |
console.log(s + ': ' + new Date() + ', ' + ' +' + (now - lastcall) + ' ' + (process.memoryUsage().rss/1024/1024) + ' Mb' + '\n'); | |
lastcall = now; | |
} | |
function sleep(n) | |
{ | |
var goal = new Date() - 0 + n*1000; | |
while ((new Date() - 0) < goal); | |
} | |
showDate('start'); | |
done = 0; len = 0; count = 0; | |
var client = net.createConnection(1234, function() { //'connect' listener | |
console.log('client connected'); | |
//client.bufferSize = 5000; | |
}); | |
client.on('data', function(data) { | |
len += data.toString().length; | |
count +=1; | |
}); | |
client.on('end', function() { | |
console.log('client disconnected'); | |
done = 1; | |
}); | |
showDate('start read'); | |
sleep(5) | |
function echo() | |
{ | |
console.log(new Date() - 0); | |
console.log(count + ': ' + len); | |
count = 0; len = 0; | |
if (!done) | |
setTimeout(echo, 10); | |
} | |
setTimeout(echo, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment