Hi Aria.
I see similar results even after using stream.on('finish'). (I removed the
async benchmark altogether.)
$ node --harmony benchmarks.js
Running benchmarks with 100000 writes
fs.writeSync took 0.32 seconds
writeStream.write took 4.073 seconds
$ node --harmony benchmarks.js
Running benchmarks with 200000 writes
fs.writeSync took 0.66 seconds
writeStream.write took 323.897 seconds
$ cat benchmarks.js
'use strict';
const fs = require('fs');
const NUM_WRITES = 200 * 1000;
const DUMMY_MESSAGE = 'Dummy log message that is about 100
characters.....................................................\n';
const DUMMY_MESSAGE_BUFFER = new Buffer(DUMMY_MESSAGE);
function benchmarkFileSync() {
var fd = fs.openSync('./dummy.log', 'w');
const startTime = new Date();
for (let i = 0; i < NUM_WRITES; i++) {
fs.writeSync(fd, DUMMY_MESSAGE);
}
const diff = (new Date() - startTime) / 1000;
console.log('fs.writeSync took', diff, 'seconds');
fs.closeSync(fd);
}
function benchmarkWriteStream() {
const stream = fs.createWriteStream(
'./dummyWriteStream.log', {
encoding: "utf8",
mode: parseInt('0644', 8)
}
);
const startTime = new Date();
for(let i = 0; i < NUM_WRITES; i++) {
let ret = stream.write(DUMMY_MESSAGE);
}
stream.end('');
stream.on('finish', function onFinish() {
const diff = (new Date() - startTime) / 1000;
console.log('writeStream.write took', diff, 'seconds');
});
}
console.log('Running benchmarks with', NUM_WRITES, 'writes');
benchmarkFileSync();
benchmarkWriteStream();
On Tuesday, May 20, 2014 10:53:40 AM UTC-7, Aria Stewart wrote:
>
>
> On May 20, 02014, at 13:29, Jeff Jolma <[email protected] <javascript:>>
> wrote:
>
> > Hello.
> >
> > I am working on a node app and found that its performance bottleneck is
> logging. And digging deeper, it looks like the root bottleneck is on the
> WriteStream.
> >
> > I ran some quick benchmarks of the WriteStream performance, and it seems
> really slow. Can someone help me understand why it is taking so long and
> if I can improve the performance? Or, maybe I am doing something wrong
> with my benchmarks.
> >
> > I get the following output running on my MacBook:
>
>
> Your benchmarks look a little suspect — setInterval rather than
> stream.on(‘finish’), and the async write case, you close the fd before you
> finish writing.
>
>
--
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/a22063be-1251-4f8f-86ce-bd6ac5fd68ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.