Bert Belder
(aka @piscisaureus)
node and libuv
read()
is calledresume()
calls read repeatedly, pause()
stops thatpipe(dest)
and on('data', fn)
resume the stream
var cluster = require('cluster');
// This is the default:
cluster.schedulingPolicy = cluster.SCHED_RR;
// .. or Set this before calling other cluster functions.
cluster.schedulingPolicy = cluster.SCHED_NONE;
// Spawn as many workers as there are CPUs in the system.
for (var i = 0, n = os.cpus().length; i < n; i += 1)
cluster.fork();
var child_process = require('child_process');
var fs = require('fs');
function execSync(command) {
// Run the command in a subshell
child_process.exec(command + ' 2>&1 1>output && echo done! > done');
// Block the event loop until the command has executed.
while (!fs.existsSync('done')) {
// Do nothing
}
// Read the output
var output = fs.readFileSync('output');
// Delete the output and done files
fs.unlinkSync('output');
fs.unlinkSync('done');
return output;
}
var spawnSync = require('child_process').spawnSync;
var result = spawnSync('cat',
['-'],
{ input: 'hello world!',
encoding: 'utf8' });
console.log('exit code: %d', result.exitCode);
console.log('output: %s', result.stdout);
console.log('error: %s', resullt.stderr);
var v8 = require('v8');
v8.cpuProfiler.setSamplingInterval(1);
v8.cpuProfiler.start();
v8.on('gc', function() {
console.log('Garbage collection just happened!');
});
Free e-book: ”Node.js in Action“
http://strongloop.com/promotions/cultivate-meetup-sf/