Skip to content

Commit

Permalink
Better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
gildean committed Aug 7, 2012
1 parent 10e3dc2 commit 716d768
Show file tree
Hide file tree
Showing 9 changed files with 9,651 additions and 5 deletions.
21 changes: 16 additions & 5 deletions README.md
@@ -1,14 +1,25 @@
BLASTER
=======

Node.js cli-app for blasting http-servers with requests.

Node.js app for blasting http-servers with requests. Cli and gui both included.
Gui-version made with appjs, so node-gyp is required (for gui only).

Usage:
------
`node blaster http://someurl ammo caliber`

url defaults to localhost, ammo defaults and caliber default to 100.
cli:
```
node blaster http://someurl ammo caliber
```

gui:
* install node-gyp with `npm install node-gyp -g`
* install appjs with `npm install appjs`
Then run the gui:
```
node --harmony app.js
```

url defaults to localhost, ammo and caliber default to 100.

(ammo = number of requests, caliber = max sockets used)

Expand Down
100 changes: 100 additions & 0 deletions app.js
@@ -0,0 +1,100 @@
var app = require('appjs')
, http = require('http')
, url = require('url');


app.serveFilesFrom(__dirname + '/content');


var window = app.createWindow({
width: 800,
height: 480,
resizable: true,
disableSecurity: true,
icons: __dirname + '/content/icons'
});


window.on('create', function(){
console.log("Window Created");
window.frame.show();
window.frame.center();
window.frame.opacity=0.92;
window.frame.showChrome=1;
});


window.on('ready', function(){
console.log("Window Ready");
window.require = require;
window.process = process;
window.module = module;
var document = window.document;
var $ = this.$,
$target = $('input[name=target]'),
$ammo = $('input[name=ammo]'),
$caliber = $('input[name=caliber]'),
$info = $('#info-target'),
$label = $info.find('span'),
$buttons = $('input, button'),
$results = $('#resultsbox');
$placeholder = $('#placeholder');
$label.text('Select target and blast!');

$('#blaster-form').submit(function(e){
e.preventDefault();
$label.text('Blasting!');
$buttons.attr('disabled', true);
var target = $target.val() || 'http://localhost',
ammo = $ammo.val() || 100,
caliber = $caliber.val() || 100;
console.log(ammo + ' ' + caliber + ' ' + target);
http.globalAgent.maxSockets = caliber;
var options = {
host: url.parse(target).hostname,
port: url.parse(target).port,
path: url.parse(target).path
};
var Data={};
var Status=new Array();
Status.push('<h2>Blasted: ' + target + ' ' + ammo + ' times</h2>');
var startTime = Date.now();

for(var i = 1; i <= ammo; i++) {
blaster(i);
};

function blaster(i) {
var req = http.get(options, function(res) {
if (i%100===0) {
Status.push('Request: ' + i + ' STATUS: ' + res.statusCode);
}
if (i == ammo) {
var endTime = Date.now();
var blastTime = (endTime - startTime)/1000;
Data=JSON.stringify(Status);
Data=eval(Data).join(",")
Data= Data.replace(/,/g,'<p>');
blastedOut(Data, blastTime);
}
}).on('error', function(e) {
Status.push('Request: ' + i + ' ERROR: ' + e.message);
if (i == ammo) {
var endTime = Date.now();
var blastTime = (endTime - startTime)/1000;
Data=JSON.stringify(Status);
Data=eval(Data).join(",")
Data= Data.replace(/,/g,'<p>');
blastedOut(Data, blastTime);
}
});
};
});

function blastedOut(Data, blastTime){
$label.text('Blasting lasted: ' + blastTime.toFixed(1));
$results.html(Data);
$buttons.attr('disabled', false);
};

});
Binary file added content/icons/128.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/icons/16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/icons/32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/icons/64.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions content/index.html
@@ -0,0 +1,28 @@
<!doctype html>
<html>
<head>
<title>blaster</title>
<link rel="stylesheet" href="style.css">
<script src="js/jquery.js"></script>
</head>
<body>
<div id="container">
<header>
<h1>blaster</h1>
</header>
<div id="blastingbox">
<form action="/" method="POST" id="blaster-form">
<input id="target" name="target" type="text" placeholder="URL"/>
<input id="ammo" name="ammo" type="number" placeholder="ammo"/>
<input id="caliber" name="caliber" type="number" placeholder="caliber"/>
<button type="submit" class="button">blast</button>
</form>
<label id="info-target">
<span></span></label>
</div>
<div id="resultsbox">
<p id="placeholder">results will appear here</span>
</div>
</div>
</body>
</html>

0 comments on commit 716d768

Please sign in to comment.