load-generator
A simple but powerful JS load generator. Generates load based on input data, an action that simulates IO, and various configurations that determine the load characteristics. Load can be randomized but still reproducible.
Example
A simple load generator can be constructed and run like this:
const { LoadGenerator, PICKING, FREQUENCY, VISIT_DATA } = require('...');
await LoadGenerator.from([1, 2, 3])
.action((n) => n * 2)
.config({
pick: PICKING.SEQUENTIAL,
frequency: FREQUENCY.RANDOM,
visit: VISIT_DATA.ONCE,
meanActionsPerSecond: 1,
})
.run();
This prints:
data: a615eeaee21de5179de080de8c3052c8da901138406ba71c38c032845f7d54f4
config: 687dfee9fb5ed0aa0fd1c92a4c84a012e18a7664b144799f6c3d12696ab164ad
generating load...
delay by 213.0170022137463ms
[i=0] running fn with data[0] 1
delay by 919.4761351682246ms
[i=1] running fn with data[1] 2
delay by 898.0880929157138ms
[i=2] running fn with data[2] 3
done generating data.
You can run this generator with yarn example [--quiet]
or npm run example -- [--quiet]
.
How-To
from
/fromGen
are static build methods that take an array or a generator to initialize the load generator with data. If no data should be used, e.g. in case the action does not have inputs, an empty array can be passed.
action
takes an (async) function that is applied to each data element and performs the IO.
config
is an object with generator configuration. These settings determine how and when load is generated, as well as under what circumstances the load generator should terminate. Through a combination of settings, complex load generators can be realized.
Configuration
-
PICK
: Whenpick
is set toSEQUENTIAL
, the data array is traversed sequentially. When set toRANDOM
, the data array is randomly traversed. If a generator function is used instead of a data array,pick
does not matter as the function dictates picking order. -
FREQUENCY
: Whenfrequency
is set toSTATIC
, load is generated in static time intervals. When set toRANDOM
, random time intervals are used. For both options, the settingmeanActionsPerSecond
determines the mean frequency of generated load. -
VISIT_DATA
: Whenvisit
is set toONCE
, each data element is used at most once. In other words, the data is exhausted. When set toREPEAT
, each data element can be used multiple times. Independent of thepick
setting, each data element is exactly used once before the data can be visited again for load generation.
Other config options:
-
seed
: A seed string used to initialize the PRNG, which determines the randomness inPICK.RANDOM
andFREQUENCY.RANDOM
. -
meanActionsPerSecond
: Effective throughput of the load generator. Applies toFREQUENCY.STATIC
as well asFREQUENCY.RANDOM
. -
maxGenerations
: The maximum number of load generations. Default: Infinity -
runFor
: The maximum time duration load should be generated in. Default: Infinity
Development
Tag a new version:
npm version [major|minor|patch] -m "chore: release %s"
CI will take care of releasing