0.0.3 • Published 5 years ago
multicannon v0.0.3
Install
npm i multicannon
Usage
multicannon = require('multicannon');
API
multicannon(opts, auth)
Start multicannon against the given target.
opts
: Array of configuration options for the multicannon instance. This can have the following attributes. REQUIRED.url
: The given target. Can be http or https. REQUIRED.socketPath
: A path to a Unix Domain Socket or a Windows Named Pipe. Aurl
is still required in order to send the correct Host header and path. OPTIONAL.connections
: The number of concurrent connections. OPTIONAL default:10
.duration
: The number of seconds to run the multicannon. Can be a timestring. OPTIONAL default:10
.amount
: ANumber
stating the amount of requests to make before ending the test. This overrides duration and takes precedence, so the test won't end until the amount of requests needed to be completed are completed. OPTIONAL.timeout
: The number of seconds to wait for a response before . OPTIONAL default:10
.pipelining
: The number of pipelined requests for each connection. Will cause theClient
API to throw when greater than 1. OPTIONAL default:1
.bailout
: The threshold of the number of errors when making the requests to the server before this instance bail's out. This instance will take all existing results so far and aggregate them into the results. If none passed here, the instance will ignore errors and never bail out. OPTIONAL default:undefined
.method
: The http method to use. OPTIONALdefault: 'GET'
.title
: AString
to be added to the results for identification. OPTIONAL default:undefined
.body
: AString
or aBuffer
containing the body of the request. Insert one or more randomly generated IDs into the body by including[<id>]
where the randomly generated ID should be inserted (Must also set idReplacement to true). This can be useful in soak testing POST endpoints where one or more fields must be unique. Leave undefined for an empty body. OPTIONAL default:undefined
.headers
: AnObject
containing the headers of the request. OPTIONAL default:{}
.setupClient
: AFunction
which will be passed theClient
object for each connection to be made. This can be used to customise each individual connection headers and body using the API shown below. The changes you make to the client in this function will take precedence over the defaultbody
andheaders
you pass in here. There is an example of this in the samples folder. OPTIONAL default:function noop () {}
.maxConnectionRequests
: ANumber
stating the max requests to make per connection.amount
takes precedence if both are set. OPTIONALmaxOverallRequests
: ANumber
stating the max requests to make overall. Can't be less thanconnections
.maxConnectionRequests
takes precedence if both are set. OPTIONALconnectionRate
: ANumber
stating the rate of requests to make per second from each individual connection. No rate limiting by default. OPTIONALoverallRate
: ANumber
stating the rate of requests to make per second from all connections.connectionRate
takes precedence if both are set. No rate limiting by default. OPTIONALreconnectRate
: ANumber
which makes the individual connections disconnect and reconnect to the server whenever it has sent that number of requests. OPTIONALrequests
: AnArray
ofObject
s which represents the sequence of requests to make while benchmarking. Can be used in conjunction with thebody
,headers
andmethod
params above. TheObject
s in this array can havebody
,headers
,method
, orpath
attributes, which overwrite those that are passed in thisopts
object. Therefore, the ones in this (opts
) object take precedence and should be viewed as defaults. Check the samples folder for an example of how this might be used. OPTIONAL.idReplacement
: ABoolean
which enables the replacement of[<id>]
tags within the request body with a randomly generated ID, allowing for unique fields to be sent with requests. Check out an example of programmatic usage can be found in the samples. OPTIONAL default:false
forever
: ABoolean
which allows you to setup an instance of multicannon that restarts indefinitely after emiting results with thedone
event. Useful for efficiently restarting your instance. To stop running forever, you must cause aSIGINT
or call the.stop()
function on your instance. OPTIONAL default:false
servername
: AString
identifying the server name for the SNI (Server Name Indication) TLS extension. OPTIONAL default:undefined
.excludeErrorStats
: ABoolean
which allows you to disable tracking non 2xx code responses in latency and bytes per second calculations. OPTIONAL default:false
.
auth
: authorization 'login:pass'
Example that just prints the table of results on completion:
const multicannon = require('multicannon');
const URLArr = [
{
url: 'http://localhost:3000/login',
connections: 10,
duration: 10
},
{
url: 'http://localhost:3000/,
connections: 10,
duration: 10
}
]
multicannon(URLArr, 'login:pass');