Comparing version 0.0.2 to 1.0.0
var wrk = require('../index.js'); | ||
wrk({ | ||
threads: 10, | ||
connections: n+1, | ||
threads: 2, | ||
connections: 5, | ||
duration: '10s', | ||
@@ -10,3 +10,6 @@ printLatency: true, | ||
}, function(err, out) { | ||
console.log(out) | ||
if (err) { | ||
console.error('err: ', err) | ||
} | ||
console.log('out: ', out) | ||
}); |
99
index.js
var exec = require('child_process').exec; | ||
var parseWrk = require('./lib/parseWrk') | ||
function wrk(opts, callback) { | ||
var cmd = opts.path || 'wrk'; | ||
if (opts.threads) | ||
cmd += ' -t' + opts.threads; | ||
if (opts.connections) | ||
cmd += ' -c' + opts.connections; | ||
if (opts.duration) | ||
cmd += ' -d' + opts.duration; | ||
if (opts.script) | ||
cmd += ' -s' + opts.script; | ||
if (opts.timeout) | ||
cmd += ' --timeout ' + opts.timeout; | ||
if (opts.printLatency) | ||
cmd += ' --latency '; | ||
cmd += ' ' + opts.url; | ||
var child = exec(cmd, function(error, stdout, stderr) { | ||
if (error) | ||
return callback(error); | ||
var cmd = opts.path || 'wrk'; | ||
var lines = stdout.split('\n'); | ||
var result = {}; | ||
result.transferPerSec = lines[lines.length - 2].split(':')[1].trim() | ||
result.requestsPerSec = Number(lines[lines.length - 3].split(':')[1].trim()) | ||
var errorsLine = 0; | ||
var errorsRe = /Socket errors: connect (\d+), read (\d+), write (\d+), timeout (\d+)/; | ||
var errorsMatch = lines[lines.length - 4].match(errorsRe); | ||
if (errorsMatch) { | ||
errorsLine = 1; | ||
result.connectErrors = errorsMatch[1]; | ||
result.readErrors = errorsMatch[2]; | ||
result.writeErrors = errorsMatch[3]; | ||
result.timeoutErrors = errorsMatch[4]; | ||
} | ||
var m = lines[lines.length - 4 - errorsLine].match(/(\d+) requests in ([0-9\.]+[A-Za-z]+), ([0-9\.]+[A-Za]+)/); | ||
result.requestsTotal = Number(m[1]); | ||
result.durationActual = m[2]; | ||
result.transferTotal = m[3]; | ||
if (opts.threads) | ||
cmd += ' -t' + opts.threads; | ||
if (opts.connections) | ||
cmd += ' -c' + opts.connections; | ||
if (opts.duration) | ||
cmd += ' -d' + opts.duration; | ||
if (opts.script) | ||
cmd += ' -s' + opts.script; | ||
if (opts.timeout) | ||
cmd += ' --timeout ' + opts.timeout; | ||
if (opts.printLatency) | ||
cmd += ' --latency '; | ||
cmd += ' ' + opts.url; | ||
var latencyMinMax = lines[3].split(/[\t ]+/); | ||
result.latencyAvg = latencyMinMax[2]; | ||
result.latencyStdev = latencyMinMax[3]; | ||
result.latencyMax = latencyMinMax[4]; | ||
result.latencyStdevPerc = Number(latencyMinMax[5].slice(0,-1)); | ||
var rpsMinMax = lines[4].split(/[\t ]+/); | ||
result.rpsAvg = Number(rpsMinMax[2]); | ||
result.rpsStdev = Number(rpsMinMax[3]); | ||
result.rpsMax = Number(rpsMinMax[4]); | ||
result.rpsStdevPerc = Number(rpsMinMax[5].slice(0,-1)); | ||
var child = exec(cmd, function(error, stdout, stderr) { | ||
if (opts.debug) { | ||
console.log('stdout:\n', stdout); | ||
console.log('stderr:\n', stderr); | ||
} | ||
if (error) { | ||
return callback(error); | ||
} | ||
if (lines[5].match(/Latency Distribution/)) { | ||
result.latency50 = lines[6].split(/[\t ]+/)[2]; | ||
result.latency75 = lines[7].split(/[\t ]+/)[2]; | ||
result.latency90 = lines[8].split(/[\t ]+/)[2]; | ||
result.latency99 = lines[9].split(/[\t ]+/)[2]; | ||
} | ||
callback(null, result); | ||
}); | ||
child.on('close', function(code, signal) { | ||
if (code === null) | ||
return callback(new Error('killed by signal: ' + signal)); | ||
// TODO: handle non-zero exit code here | ||
}); | ||
callback(null, parseWrk(stdout)); | ||
}); | ||
child.on('close', function(code, signal) { | ||
if (code === null) { | ||
return callback(new Error('killed by signal: %s', signal)); | ||
} | ||
if (code !== 0) { | ||
return callback(new Error('died with exit code: %s', code)); | ||
} | ||
}); | ||
} | ||
@@ -75,4 +48,4 @@ | ||
return function(callback) { | ||
wrk(opts, callback); | ||
wrk(opts, callback); | ||
} | ||
} |
{ | ||
"name": "wrk", | ||
"version": "0.0.2", | ||
"version": "1.0.0", | ||
"description": "wrk load test tool wrapper and output parser", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "" | ||
"test": "tap test/*.tap.js" | ||
}, | ||
@@ -18,3 +18,19 @@ "repository": { | ||
"author": "Andrey Sidorov <sidorares@yandex.ru>", | ||
"license": "MIT" | ||
"contributors": [ | ||
"Wraithan <xwraithanx@gmail.com> (http://wraithan.net)" | ||
], | ||
"license": "MIT", | ||
"devDependencies": { | ||
"tap": "^0.4.13" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/sidorares/node-wrk/issues" | ||
}, | ||
"homepage": "https://github.com/sidorares/node-wrk", | ||
"directories": { | ||
"lib": "lib", | ||
"test": "test", | ||
"example": "example" | ||
}, | ||
"dependencies": {} | ||
} |
# node-wrk | ||
Prepare command line arguments and parse the output of the [wrk](https://github.com/wg/wrk) load testing tool | ||
Prepare command line arguments and parse the output of the | ||
[wrk](https://github.com/wg/wrk) load testing tool | ||
# example | ||
@@ -13,7 +15,8 @@ | ||
function benchmark() { | ||
if (n == 100) | ||
return console.log(JSON.stringify(results)); | ||
if (conns === 100) { | ||
return console.log(results); | ||
} | ||
conns++; | ||
wrk({ | ||
threads: 10, | ||
threads: 1, | ||
connections: conns, | ||
@@ -38,4 +41,7 @@ duration: '10s', | ||
- `path`: path to wrk binary (default is "wrk") | ||
- `debug`: print the output of `wrk` to stdout | ||
Callback parameters: (err, wrkResults) where wrkResults is a hash with | ||
Callback parameters: (err, wrkResults) | ||
wrkResults always has: | ||
- transferPerSec | ||
@@ -50,2 +56,8 @@ - requestsPerSec | ||
- latencyMax | ||
- rpsAvg | ||
- rpsMax | ||
- rpsStdev | ||
- rpsStdevPerc | ||
Has these if `printLatency` is enabled | ||
- latency50 | ||
@@ -55,6 +67,4 @@ - latency75 | ||
- latency99 | ||
- rpsAvg | ||
- rpsMax | ||
- rpsStdev | ||
- rpsStdevPerc | ||
And sometimes has (only if they exist): | ||
- connectErrors | ||
@@ -64,2 +74,3 @@ - readErrors | ||
- timeoutErrors | ||
- non2xx3xx | ||
@@ -66,0 +77,0 @@ # install |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
10362
8
223
0
0
86
1
3