Skip to content

Instantly share code, notes, and snippets.

@sreepurnajasti
Last active February 15, 2017 12:15
Show Gist options
  • Save sreepurnajasti/b227659452744c33d60fc9c4e52276e2 to your computer and use it in GitHub Desktop.
Save sreepurnajasti/b227659452744c33d60fc9c4e52276e2 to your computer and use it in GitHub Desktop.
A testcase which can holds to 128* 100 connections parllely and matching the data chunk with a specified word and storing its word count in a file.
var http = require('http');
var util = require('util');
var fs = require("fs");
var string = 'http://' + process.argv[2] + ':' + process.argv[3] + '/';
var out = fs.createWriteStream('./out.txt');
var start = process.hrtime();
function mapreduce(d){
var result = d.toString().match(/node/g);
if(result != null)
out.write(result.length.toString() + '\n');
}
for(var count=0;count<process.argv[4];count++) {
http.get(string, (res) => {
res.on('data', (d) => {
mapreduce(d);
});
res.on('end', () => {
repeat(99);
});
});
}
function repeat(index) {
if(index == 0) return;
http.get(string, (res) => {
res.on('data', (d) => {
mapreduce(d);
});
res.on('end', () => {
repeat(index - 1);
});
});
}
process.on('exit', function() {
var diff = process.hrtime(start);
console.log(Math.round((diff[0] * 1e9 + diff[1]) / 1000000) + ' millis.');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment