4

多个进程可以使用 writestream 将数据写入同一个文件吗?性能影响和数据丢失怎么样?

var fs = require('fs');
var cluster = require('cluster');
if(cluster.isMaster){
for(var i=0;i<10; i++)
{
    var child = cluster.fork();
}
}
else{
var stream = fs.createWriteStream('data.txt', {flags:'a'});
stream.on('error', function(error){
    console.log(process.pid+' error occured', error);
})
stream.write(process.pid+' msg\n');
//lots of writes
}
4

0 回答 0