Socket
Book a DemoInstallSign in
Socket

load-gen

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

load-gen

[![CI](https://github.com/mohoff/load-generator/actions/workflows/ci.yml/badge.svg)](https://github.com/mohoff/load-generator/actions/workflows/ci.yml)

0.0.7
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

load-generator

CI

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: When pick is set to SEQUENTIAL, the data array is traversed sequentially. When set to RANDOM, 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: When frequency is set to STATIC, load is generated in static time intervals. When set to RANDOM, random time intervals are used. For both options, the setting meanActionsPerSecond determines the mean frequency of generated load.

  • VISIT_DATA: When visit is set to ONCE, each data element is used at most once. In other words, the data is exhausted. When set to REPEAT, each data element can be used multiple times. Independent of the pick 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 in PICK.RANDOM and FREQUENCY.RANDOM.
  • meanActionsPerSecond: Effective throughput of the load generator. Applies to FREQUENCY.STATIC as well as FREQUENCY.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

FAQs

Package last updated on 26 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.