Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wrk

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wrk - npm Package Compare versions

Comparing version 0.0.2 to 1.0.0

lib/parseWrk.js

9

example/example.js
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)
});
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc