joyent/node — pull request #4518 by shigeki (2013-01-04 17:07:52+00:00)
Title: fs: pool size coincide with ReadStream bufferSize

pool size of file reading in ReadableStream was statically set 40k. It can be adjustable with a bufferSize option for performace tuning of file read.
Benchmarking results in reading/writing file stream of 100Mbyte are below.

````
// fs_stream_bench.js
var fs = require('fs');
var infile = '/home/ohtsu/tmp/100M.file';
var outfile = infile + '.out';
var kB = 1024;
var bufferSizeList = [2 * 64 * kB, 3 * 64 * kB, 4 * 64 * kB, 5 * 64 * kB];

function fsStreamBench(bufferSize) {
var option = {};
if (bufferSize) option.bufferSize = bufferSize;
if (fs.existsSync(outfile)) fs.unlinkSync(outfile);

var rstream = fs.createReadStream(infile, option);
var wstream = fs.createWriteStream(outfile);

var start = Date.now();
rstream.pipe(wstream);

wstream.on('finish', function() {
var bufSize = rstream._readableState.bufferSize;
console.log('bufferSize:', bufSize, ', time:', Date.now() - start);
if (bufferSizeList.length) fsStreamBench(bufferSizeList.shift());
});
}

fsStreamBench();
````
````
# node-v0.9.5
> ./node ~/tmp/fs_stream_bench.js
bufferSize: 65536 , time: 307
bufferSize: 131072 , time: 287
bufferSize: 196608 , time: 274
bufferSize: 262144 , time: 277
bufferSize: 327680 , time: 320

# after this commit
> ./node ~/tmp/fs_stream_bench.js
bufferSize: 65536 , time: 255
bufferSize: 131072 , time: 196
bufferSize: 196608 , time: 156
bufferSize: 262144 , time: 170
bufferSize: 327680 , time: 139
````

And another commit to remove unsed bufferSize option in WriteStream was added.