wrk Load Test Tool Wrapper

1.2.1 · abandoned · verified Tue Apr 21

The `wrk` Node.js package serves as a wrapper for the popular `wrk` HTTP benchmarking command-line tool. It enables developers to programmatically execute load tests and parse the output directly within a Node.js environment, simplifying the integration of performance testing into applications or CI/CD pipelines. This package allows configuration of `wrk` parameters such as threads, connections, and test duration, and then processes the `wrk` tool's raw output into a structured JavaScript object containing detailed performance metrics like requests per second, latency statistics, and transfer rates. Currently at version 1.2.1, the package was last published in September 2020, indicating it is no longer actively maintained. Its primary utility lies in abstracting the `child_process` execution and output parsing, but it critically depends on the `wrk` CLI tool being pre-installed on the system and accessible in the PATH.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `node-wrk` package to perform a series of load tests, incrementally increasing the number of concurrent connections. It shows how to configure `wrk` options, handle the callback, and accumulate results, providing a basic framework for performance analysis.

const wrk = require('wrk');

let conns = 1;
const results = [];

function benchmark() {
  if (conns === 100) {
    // In a real scenario, you'd process these results,
    // e.g., save to a file, aggregate, or display.
    console.log('--- Benchmark Complete ---');
    results.forEach((res, index) => {
      console.log(`
Test with ${res.connections} connections:`);
      console.log(`  Requests/Sec: ${res.requestsPerSec}`);
      console.log(`  Latency Avg: ${res.latencyAvg}`);
    });
    return;
  }
  
  console.log(`Running test with ${conns} connections...`);
  wrk({
    threads: 1,
    connections: conns,
    duration: '1s',
    printLatency: true,
    headers: { 'User-Agent': 'node-wrk-benchmark' },
    url: 'http://localhost:3000/' // Ensure a server is running here, e.g., 'python3 -m http.server 3000'
  }, function(err, out) {
     if (err) {
       console.error('wrk error:', err);
       // Often 'spawn wrk ENOENT' if the wrk CLI tool is not installed or in PATH
       return;
     }
     results.push(out);
     conns++;
     benchmark();
  });
}

// To run this example, ensure the `wrk` CLI tool is installed (e.g., `brew install wrk` on macOS)
// and a simple HTTP server is running on http://localhost:3000.
// You can start a simple Python server with: `python3 -m http.server 3000`

benchmark();

view raw JSON →