Repository: doubaokun/node-ab
Branch: master
Commit: 532cd76aba04
Files: 7
Total size: 9.1 KB
Directory structure:
gitextract_1g0c9lgj/
├── .gitignore
├── LICENSE-MIT
├── README.md
├── bin/
│ └── nab
├── lib/
│ └── ab.js
├── package.json
└── sample/
└── app.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
node_modules
npm-debug.log
================================================
FILE: LICENSE-MIT
================================================
Copyright (c) 2013 "Bruce Dou" <doubaokun@gmail.com>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
================================================
FILE: README.md
================================================
## Node ab testing
Automatically benchmarking the performance of HTTP services.

## How it works
Ab testing tool to check the performance of an HTTP service. 100 more GET request will be increased per second. It will not increase more request if there are more than 10 request not returned. It will stop when there are less than 99% request return successful.
The requests number per increase round and the time of each round can be changed by user.
## Installation:
sudo npm install node-ab -g
## Usage:
nab [URL] [--increase 100] [--milliseconds 1] [--help] [--verbose]
nab --help
Usage: nab <URL> [--increase 100] [--milliseconds 1] [--help] [--verbose]
Samples:
nab http://192.168.1.66
nab http://localhost
nab http://localhost:4000 --increase 200
nab http://localhost:4000 -i 200
nab http://localhost:4000 --milliseconds 1500
nab http://localhost:4000 --milliseconds 1500 --verbose
nab http://localhost:4000 -m 1500
nab http://localhost:4000 -m 1500 -v
nab --help
nab -h
## Example:
nab http://localhost:4000/test
Request number: 200 Return number: 200 QPS: 66 Traffic: 32KB per second
Request number: 800 Return number: 800 QPS: 133 Traffic: 65KB per second
Request number: 1700 Return number: 1700 QPS: 188 Traffic: 92KB per second
Request number: 2900 Return number: 2900 QPS: 241 Traffic: 117KB per second
Request number: 4400 Return number: 4400 QPS: 293 Traffic: 143KB per second
Request number: 6200 Return number: 6200 QPS: 344 Traffic: 168KB per second
Request number: 8300 Return number: 8300 QPS: 394 Traffic: 192KB per second
Request number: 10700 Return number: 10700 QPS: 445 Traffic: 217KB per second
Request number: 13400 Return number: 13400 QPS: 495 Traffic: 242KB per second
Request number: 16400 Return number: 16366 QPS: 545 Traffic: 266KB per second
Request number: 16400 Return number: 16366 QPS: 495 Traffic: 241KB per second
Request number: 16400 Return number: 16366 QPS: 454 Traffic: 221KB per second
Request number: 16400 Return number: 16366 QPS: 419 Traffic: 204KB per second
Request number: 16400 Return number: 16366 QPS: 389 Traffic: 190KB per second
Request number: 18400 Return number: 18268 QPS: 405 Traffic: 198KB per second
Request number: 21400 Return number: 21009 QPS: 437 Traffic: 213KB per second
## Development
git clone git@github.com:doubaokun/node-ab.git
npm install -d
### Start a sample http service at http://127.0.0.1:4000/test
node sample/app.js
### Start testing the sample http service
./bin/nab http://localhost:81/test
================================================
FILE: bin/nab
================================================
#!/usr/bin/env node
require("../lib/ab.js")
================================================
FILE: lib/ab.js
================================================
var httpLib = require('http'),
url = require('url'),
colors = require('colors'),
argv = require('optimist').argv;
var stats = {
'conn_num': 0,
'req_num': 0,
'success_num': 0,
'traffic_ps': 0
};
if(argv.help || argv.h){
console.log("Usage: nab <URL> [--increase 100] [--milliseconds 1] [--help] [--verbose]".green);
console.log("");
console.log("Samples:".blue);
console.log("\tnab http://192.168.1.66");
console.log("\tnab http://localhost");
console.log("\tnab http://localhost:4000 --increase 200");
console.log("\tnab http://localhost:4000 -i 200");
console.log("\tnab http://localhost:4000 --milliseconds 1500");
console.log("\tnab http://localhost:4000 --milliseconds 1500 --verbose");
console.log("\tnab http://localhost:4000 -m 1500");
console.log("\tnab http://localhost:4000 -m 1500 -v");
console.log("\tnab --help");
console.log("\tnab -h");
return console.log("");
}
if(!process.argv[2]) {
return console.log("Usage: nab <URL> [--increase 100] [--milliseconds 1] [--help] [--verbose]".red);
}
var uri = process.argv[2];
var user_option = url.parse(uri);
if(!user_option.hostname || !user_option.path) {
return console.log("Not validate [URL]".red);
}
var useHTTPS = (user_option.protocol === 'https:');
if (useHTTPS) {
httpLib = require('https');
}
var force = (argv.increase || argv.i) || 100; // increase request number per second
if(argv.v || argv.verbose) console.log(("Increase " + (force) + " requests per round").green);
var pre_qps = 0;
var traffic = 0;
var start = new Date().getTime();
process.on('uncaughtException', function (err) {
// continue running
//console.error(err.stack);
if(argv.v || argv.verbose) console.log(("Ending connection").red);
});
var bench_intv = function() {
// Skip when there are no return requests
if(stats.conn_num > 10) return;
var http_request = function() {
var options = {
hostname: user_option.hostname,
port: user_option.port,
path: user_option.path,
method: 'GET'
};
if (useHTTPS) {
options.rejectUnauthorized = false;
}
var callback = function(res) {
if(res.statusCode === 200) {
stats.success_num ++;
}
res.setEncoding('utf8');
res.on('data', function (chunk) {
if(argv.v || argv.verbose){
console.log(("Data received").green);
console.log(("\t"+chunk).yellow);
}
traffic += chunk.length;
});
res.on('end', function() {
if(argv.v || argv.verbose)console.log(("Ending connection").red);
stats.conn_num --;
});
};
var req = httpLib.request(options, callback);
req.setNoDelay(true);
//req.setSocketKeepAlive(false);
req.end();
};
for(var i=0; i< force; i++) {
stats.req_num ++;
stats.conn_num ++;
http_request();
}
};
var milliseconds = (argv.milliseconds || argv.m) || 1000;
if(argv.v || argv.verbose) console.log(("Increase requests per " + milliseconds + " milliseconds").green);
setInterval(bench_intv, milliseconds );
var stats_intv = function() {
var qps = parseInt(stats.success_num * milliseconds / (new Date().getTime() - start), 10);
stats.qps = qps;
stats.force = force;
var tps = parseInt(traffic * milliseconds / (new Date().getTime() - start), 10);
stats.traffic_ps = btraffic(tps);
console.log("Request number: " + stats.req_num.toString().green + " Return number: " + stats.success_num.toString().green
+ " QPS: " + stats.qps.toString().green + " Traffic: " + stats.traffic_ps.green);
if(stats.req_num - stats.success_num < 10) {
force += 100;
}
if(stats.success_num/stats.req_num < 0.99) {
process.exit();
}
if(stats.qps === pre_qps) {
process.exit();
}
pre_qps = qps;
};
setInterval(stats_intv, 3*milliseconds);
function btraffic(num) {
var m = parseInt(num / 1048576, 10);
var k = parseInt((num - m * 1048576) / 1024, 10);
var b = parseInt(num - m * 1048576 - k * 1024, 10);
var result = '';
if(m > 0) {
result += m + 'MB ';
}
if(k > 0 && !result) {
result += k + 'KB ';
}
if(b > 0 && !result) {
result += b + 'B ';
}
if(milliseconds == 1000){
result += 'per second';
}else{
result += 'every ' + (milliseconds) + ' milliseconds';
}
return result;
}
================================================
FILE: package.json
================================================
{
"name": "node-ab",
"version": "0.0.6",
"description": "A command tool to test the performance of HTTP services.",
"bin": {
"nab": "./bin/nab"
},
"dependencies": {
"colors": "~0.6.0",
"optimist": "^0.6.1",
"express": "*"
},
"repository": {
"type": "git",
"url": "git://github.com/doubaokun/node-ab"
},
"keywords": [
"ab",
"performance",
"testing",
"http"
],
"author": "Bruce Dou <doubaokun@gmail.com>",
"url": "https://github.com/doubaokun/node-ab/blob/master/LICENSE-MIT"
}
================================================
FILE: sample/app.js
================================================
var cluster = require('cluster');
var numCPUs = /*require('os').cups().length*/ 8;
var express = require('express');
if(cluster.isMaster) {
for(var i = 0; i < numCPUs; i++) {
cluster.fork();
}
console.log("Server started http://127.0.0.1:4000/test");
} else {
var app = express();
app.get('/test', function(req, res) {
var body = '';
for(var i=0;i<100;i++) {
body += 'aaaaa';
}
res.end(body);
});
app.listen(4000);
}
gitextract_1g0c9lgj/
├── .gitignore
├── LICENSE-MIT
├── README.md
├── bin/
│ └── nab
├── lib/
│ └── ab.js
├── package.json
└── sample/
└── app.js
SYMBOL INDEX (1 symbols across 1 files)
FILE: lib/ab.js
function btraffic (line 130) | function btraffic(num) {
Condensed preview — 7 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (10K chars).
[
{
"path": ".gitignore",
"chars": 97,
"preview": "lib-cov\n*.seed\n*.log\n*.csv\n*.dat\n*.out\n*.pid\n*.gz\n\npids\nlogs\nresults\nnode_modules\n\nnpm-debug.log\n"
},
{
"path": "LICENSE-MIT",
"chars": 1076,
"preview": "Copyright (c) 2013 \"Bruce Dou\" <doubaokun@gmail.com>\n\nPermission is hereby granted, free of charge, to any person\nobtain"
},
{
"path": "README.md",
"chars": 2767,
"preview": "## Node ab testing\n\nAutomatically benchmarking the performance of HTTP services.\n\n"
},
{
"path": "lib/ab.js",
"chars": 4340,
"preview": "var httpLib = require('http'),\n url = require('url'),\n colors = require('colors'),\n argv = require('optimist')."
},
{
"path": "package.json",
"chars": 542,
"preview": "{\n \"name\": \"node-ab\",\n \"version\": \"0.0.6\",\n \"description\": \"A command tool to test the performance of HTTP services.\""
},
{
"path": "sample/app.js",
"chars": 462,
"preview": "var cluster = require('cluster');\nvar numCPUs = /*require('os').cups().length*/ 8;\nvar express = require('express');\n\nif"
}
]
About this extraction
This page contains the full source code of the doubaokun/node-ab GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 7 files (9.1 KB), approximately 2.8k tokens, and a symbol index with 1 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.