Or even simplier

 (function doWrite(){
    if(i--) stream.write(DUMMY_MESSAGE,doWrite);
    else stream.end('');
  })();


2014-05-20 22:45 GMT+03:00 Denys Khanzhyiev <[email protected]>:

> this variant is more efficient.
>
> function benchmarkWriteStream() {
>   const stream = fs.createWriteStream(
>     './dummyWriteStream.log', {
>       encoding: "utf8",
>       mode: parseInt('0644', 8)
>     }
>   );
>
>   const startTime = new Date();
>
>   var i = NUM_WRITES;
>   (function doWrite(){
>     if(i--) {
>       var ret = stream.write(DUMMY_MESSAGE);
>       if(!ret) stream.once('drain',doWrite);
>       else doWrite();
>     }
>     else stream.end('');
>   })();
>
>
>   stream.on('finish', function onFinish() {
>     const diff = (new Date() - startTime) / 1000;
>     console.log('writeStream.write took', diff, 'seconds');
>   });
> }
>
> though it is 2 times slower than sync variant
>
>
> 2014-05-20 21:52 GMT+03:00 Forrest Norvell <[email protected]>:
>
>  I am surprised at the performance hit this buffering causes. Should it
>> really take 4.5 seconds to write 100,000 lines and 290 seconds to write
>> 200,000 lines?
>>
>> Node 0.12 will have better support for writev / corking and uncorking,
>> which will allow you to coalesce writes and regain some of the efficiency
>> lost by the individual writes ignoring fs buffering (although it doesn’t
>> look like fs.createWriteStream() returns a stream that coalesces by
>> default, so you’ll have to write your own). Which is, I suspect, the source
>> of the lag you’re seeing – each write to the stream has to succeed and be
>> acknowledged before the next one can be performed, whereas fs.write() /
>> fs.writeSync() are writing to the fs’s buffer. The difference is going
>> to be especially pronounced with an append-only file like a log.
>>
>> F
>> ​
>>
>> --
>> Job board: http://jobs.nodejs.org/
>> New group rules:
>> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
>> Old group rules:
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "nodejs" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/nodejs/CAHG3qKrMqwNPKYLM-joR9oOuWENQvd4wqXQ1zd9QwPh5p%2BmxuA%40mail.gmail.com<https://groups.google.com/d/msgid/nodejs/CAHG3qKrMqwNPKYLM-joR9oOuWENQvd4wqXQ1zd9QwPh5p%2BmxuA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAP8%3DUySOtvnOi1DwbCUydvJKQQi_P%2BdLv9PTndVT86G6PoFk4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to