使用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
}