npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

inefficient

v1.2.0

Published

Stress generation middleware to load CPU and memory.

Downloads

2

Readme

inefficient

Load generation middleware to dynamically load CPU and memory via URL params.

By design, this code is extremely inefficient. Don't use this module on production environments or leave it exposed on a public-facing server if you don't want to get a surprise bill or suffer a trivial denial of service attack.

Motivation

Used in non-production environments to verify Node.js memory limits and Kubernetes horizontal pod autoscalers rules that rely on custom metrics based on memory, CPU, or average response times.

Usage

Choose a hard to guess unique endpoint for the stress test:

export DANGEROUSLY_INEFICCIENT_ENDPOINT=_aNonGuessableInefficientEndpoint

Via a Node.js app

Using a connect-compatible framework such as Express.js conditionally enable the following middleware

if (process.env.DANGEROUSLY_INEFICCIENT_ENDPOINT) {
  app.get(
    `/${process.env.DANGEROUSLY_INEFICCIENT_ENDPOINT}`,
    require('inefficient')
  );
}

Via the public docker image

docker run \
  -e "DANGEROUSLY_INEFICCIENT_ENDPOINT=${DANGEROUSLY_INEFICCIENT_ENDPOINT}" \
  -it --rm \
  -p 3000:3000 \
  bermi/inefficient

Then using a tool like siege:

siege -r 100 \
  "http://localhost:3000/${DANGEROUSLY_INEFICCIENT_ENDPOINT}?memory=800"

to fill up to 800MB worth of RAM on each one of the nodes on your cluster call:

siege "http://localhost:3000/${DANGEROUSLY_INEFICCIENT_ENDPOINT}?cpu=1"

to generate CPU load. You can increment cpu= up to 10 at which point the server can collapse or become extremely unresponsive.

URL parameters

The middleware allows parameterizing the memory and CPU-stress levels via the following arguments.

mbPerCall: number

Defines the amount of RAM to leak on every call until the limit determined by the memory parameter.

Defaults to 1MB

memory: number

The maximum memory to leak.

Defaults to 800MB

cpu: number

Defines the number of chunks to take from the memory leaked array to marshal/unmarshal to generate CPU load.

The CPU load originates from the following call:

JSON.parse(JSON.stringify(global._memoryLeaker.slice(0, +cpu)))

Where global._memoryLeaker contains an array of strings with their size defined by the mbPerCall option.

A large mbPerCall and cpu results in long CPU blocking times and slower response times.

Defaults to 0

unleakMemory: boolean

Set to true go free up leaked memory.