Skip to content

Commit

Permalink
Flood script, upgraded
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo López committed Mar 26, 2014
1 parent 4b3a903 commit ca6e9a6
Showing 1 changed file with 46 additions and 30 deletions.
76 changes: 46 additions & 30 deletions test/jmeter_auxtools/flood-push-server.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* jshint node: true */
"use strict";
'use strict';

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

var request = require('request');
var http = require('http');
http.globalAgent.maxSockets = 20000;
var https = require('https');
var url = require('url');
https.globalAgent.maxSockets = 20000;

function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
Expand All @@ -28,8 +31,10 @@ var finishing = false;

var HELLOS_RECEIVED = 0;
var REGISTER_RECEIVED = 0;
var NOTIFICATIONS_SENT = 0;
var NOTIFICATIONS_SENT_OK = 0;
var NOTIFICATIONS_RECEIVED = 0;
var NOTIFICATIONS_TRIED = 0;
var NOTIFICATIONS_SENT_BAD = 0;


var debug = function(message) {
Expand All @@ -42,36 +47,46 @@ var sendRegister = function(connection) {

var sendNotification = function(idcon, where, version) {
if (!where || !version || finishing) return;
NOTIFICATIONS_SENT++;
var u = url.parse(where);
NOTIFICATIONS_TRIED++;
var options = {
hostname: u.hostname,
port: u.port,
path: u.path,
url: where,
method: 'PUT',
agent: new https.Agent(false)
agent: false,
pool: {
maxSockets: 40000
},
headers: {
'Connection': 'close'
},
body: 'version=' + version
};

var req = https.request(options, function(res) {
debug('(conn ' + idcon + ') notification sent to url=' + where + ' version=' + version + ' - ' + res.statusCode);
request(options, function(error, message/*, response*/) {
if (error) {
debug('(conn ' + idcon + ') error sending!! ' + require('util').inspect(error));
NOTIFICATIONS_SENT_BAD++;
return;
}
if (message && (message.statusCode === 200)) {
debug('(conn ' + idcon + ') notification sent to url=' + where + ' version=' +
version + ' - ' + message.statusCode);
NOTIFICATIONS_SENT_OK++;
} else {
debug('(conn ' + idcon + ') notification ERROR to url=' + where + ' version=' +
version + ' - ' + message.statusCode);
NOTIFICATIONS_SENT_BAD++;
}
});

req.on('error', function(e){
debug('error sending!!' + e);
});



req.write('version=' + version);
req.end();
};

var wsClient = require('websocket').client;

var ARGS = [];
if (process.argv.length < 9) {
console.error('You must use 7 parameters, like this');
console.error('node script.js <IP> <Port> <Number of conn> <Interval between start connections> <ACK delay> <Notification interval> <Time to kill>');
console.error('node script.js <IP> <Port> <Number of conn> ' +
'<Interval between start connections> <ACK delay> ' +
'<Notification interval> <Time to kill>');
console.error('all intervals are in milliseconds');
process.exit(1);
}
Expand All @@ -81,11 +96,11 @@ if (process.argv[8] < 5000) {
process.exit(1);
}

for (var i = 2; i<process.argv.length; i++) {
for (var i = 2; i < process.argv.length; i++) {
ARGS.push(process.argv[i]);
}

var WSADRESS = 'wss://'+ARGS[0]+':'+ARGS[1]+'/',
var WSADRESS = 'wss://' + ARGS[0]+':'+ARGS[1]+'/',
PROTOCOL = 'push-notification';

var newConnection = function newConnection() {
Expand Down Expand Up @@ -131,7 +146,7 @@ var newConnection = function newConnection() {
debug('(conn ' + identifier + ') received register');
} else if (json.messageType === 'notification') {
poolMessages[identifier]++;

json.updates.forEach(function(e) {
debug('(conn ' + identifier + ') received notification version=' + e.version);
});
Expand All @@ -152,7 +167,7 @@ var newConnection = function newConnection() {
poolConnections[identifier] = null;
return;
}
sendNotification(identifier, connection.pushEndpoint, Math.floor(Math.random()*100000));
sendNotification(identifier, connection.pushEndpoint, Math.floor(Math.random() * 100000));
}, ARGS[5]);
INTERVALS.push(interval);
});
Expand Down Expand Up @@ -186,7 +201,7 @@ setTimeout(function checkAliveConnections() {
conn.sendUTF('{}');
}
});
}, ARGS[6]-140000);
}, ARGS[6] - 140000);

setTimeout(function killItWithFire() {
console.log('------------------ Summary ------------------');
Expand All @@ -196,10 +211,11 @@ setTimeout(function killItWithFire() {
console.log('Actual open connections=' + Object.keys(poolPong).length);
console.log('Hellos received=' + HELLOS_RECEIVED);
console.log('Endpoints received=' + REGISTER_RECEIVED);
console.log('Notifications sent=' + NOTIFICATIONS_SENT);
console.log('Tried notifications=' + NOTIFICATIONS_TRIED);
console.log('Notifications sent OK=' + NOTIFICATIONS_SENT_OK);
console.log('Notifications sent BAD=' + NOTIFICATIONS_SENT_BAD);
console.log('Notifications received=' + NOTIFICATIONS_RECEIVED);
console.log('All in just ' + ARGS[6]/1000 + ' seconds!!');
console.log('All in just ' + ARGS[6] / 1000 + ' seconds!!');
console.log('------------------ Summary ------------------');
process.exit();
}, ARGS[6]);

0 comments on commit ca6e9a6

Please sign in to comment.