fastcgi-stream
Version:
Fast FastCGI Stream wrapper for reading/writing FCGI records.
38 lines (27 loc) • 1.22 kB
JavaScript
/* eslint no-console:0 */
;
var streamBuffers = require('stream-buffers');
var fastcgi = require('../lib');
var createRecords = function(constructor, num) {
num = num || 1000;
// Make a write buffer big enough to fit everything.
var writeStream = new streamBuffers.WritableStreamBuffer({
});
var fastcgiStream = new fastcgi.FastCGIStream(writeStream);
var start = Date.now();
var running = true;
var i = 1;
setTimeout(function() {
running = false;
console.log('Took ' + (Date.now() - start) + 'ms to write ' + i + ' records');
console.log('Buffer has ' + writeStream.size() + ' bytes.');
}, 1000);
var doWrite = function() {
fastcgiStream.writeRecord(i++, constructor());
if(running) process.nextTick(doWrite);
};
process.nextTick(doWrite);
};
//createRecords(function() { return new fastcgi.records.BeginRequest(Math.floor(Math.random()*300000 + 1), Math.floor(Math.random()*255 + 1)); }, 10000);
var myParams = [['LOLOLOLOLOL', 'HAHAHAHA'], ['LOLOLOLOLOL', 'HAHAHAHA'], ['LOLOLOLOLOL', 'HAHAHAHA'], ['LOLOLOLOLOL', 'HAHAHAHA'], ['LOLOLOLOLOL', 'HAHAHAHA']];
createRecords(function() { return new fastcgi.records.Params(myParams); }, 10000);