New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

wave-threaded-server

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

wave-threaded-server

Full-stack library combining wave-driven server concurrency with client-side routing

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

wave-threaded-server

A wave-driven concurrency controller for Node.js using Express and worker threads. Designed to adaptively manage load using a configurable wave shape, backpressure, and automatic worker scaling.

Ideal for stateless task processing under fluctuating load using adaptive concurrency control.

Features

  • 🌊 Wave-based concurrency: Controls worker count using a sine wave model with load-aware shaping.
  • 🔁 Backpressure queueing: Smoothly queues excess requests and avoids overload.
  • ⚙️ Stateless task execution: Distributes tasks via worker threads with retries and failure tracking.
  • 📈 Adaptive tuning: Adjusts wave amplitude/period based on latency feedback.
  • 🔍 Built-in metrics & healthcheck: Easily monitor performance and status.

Installation

npm install wave-threaded-server

Usage

1. Setup an Express App

const express = require('express');
const {
  WaveController,
  waveMiddleware,
  runStatelessTask,
  exposeMetrics,
  exposeHealthCheck
} = require('wave-threaded-server');

const app = express();
const wave = new WaveController();

app.locals.taskFn = async (x) => {
  // Simulate async computation
  await new Promise(r => setTimeout(r, 50));
  return x * 2;
};

app.use(waveMiddleware({ waveController: wave }));

// Stateless route (uses worker threads)
app.get('/compute', async (req, res, next) => next());

// Optional: Metrics and health endpoints
exposeMetrics(app);
exposeHealthCheck(app);

app.listen(3000, () => console.log('Server running on port 3000'));

2. Test It

curl http://localhost:3000/compute

API

WaveController(options)

Adaptive concurrency controller.

  • options.period: Wave period in ms.
  • options.amplitude: Maximum number of workers.
  • options.offset: Phase offset in ms.
  • options.shapeFn(phase): Custom wave shape (optional).

waveMiddleware({ waveController, isStateless })

Middleware that routes GET/POST differently and applies backpressure queueing.

runStatelessTask(data, waveController)

Runs a task in a worker thread with retries and backoff.

await runStatelessTask({ value: 10 }, wave);

exposeMetrics(app, path?)

Adds a /metrics route returning wave and worker stats.

exposeHealthCheck(app, path?)

Adds a /health route returning a basic health status.

Environment Variables

NameDescriptionDefault
WAVE_PERIODWave period in ms10000
WAVE_AMPLITUDEMax concurrencyCPU count
WAVE_MIN_THREADSMinimum concurrency1
WAVE_LATENCY_TARGET_MSTarget latency200
WAVE_QUEUE_MAX_SIZEMax queue size1000

License

MIT

Keywords

concurrency

FAQs

Package last updated on 25 Apr 2025

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