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 🙏

© 2025 – Pkg Stats / Ryan Hefner

knock-mq

v0.0.8

Published

Production-grade message queue implementation.

Readme

Knock

A production-grade message queue implementation.

Features

  • High Performance: 354 jobs/sec enqueue rate with realistic processing
  • Production Ready: Circuit breaker, retries, dead letter queue
  • Type Safe: Full TypeScript support with comprehensive type definitions
  • Flexible Storage: In-memory storage with extensible interface for other backends
  • Priority Queues: Support for high, normal, and low priority jobs
  • Monitoring: Built-in metrics and health monitoring
  • Realistic Testing: Comprehensive test suite with production-like scenarios

Installation

npm install knock-mq

Quick Start

import { Queue, Storage } from 'knock-mq';

// Create a queue instance
const queue = new Queue({
  name: 'my-queue',
  storage: new Storage(),
  maxRetries: 3,
  maxConcurrent: 5,
  logger: console
});

// Add a job processor
queue.useProcessor(async (job) => {
  console.log('Processing job:', job.data);
  // Your job processing logic here
  return { success: true };
});

// Start processing
queue.start();

// Add jobs to the queue
await queue.enqueue({ message: 'Hello, World!' });
await queue.enqueue({ urgent: true }, { priority: 'high' });

API Reference

Queue

The main interface for interacting with the queue.

import { Queue } from 'knock-mq';

const queue = new Queue({
  concurrency: 10,        // Number of concurrent jobs
  retryAttempts: 3,       // Retry failed jobs
  retryDelay: 1000,       // Delay between retries (ms)
  circuitBreakerThreshold: 5  // Circuit breaker failure threshold
});

Methods

  • add(jobType, data, options?) - Add a job to the queue
  • process(jobType, processor) - Register a job processor
  • start() - Start processing jobs
  • stop() - Stop processing jobs
  • pause() - Pause the queue
  • resume() - Resume the queue
  • getStats() - Get queue statistics

Queue

Low-level queue implementation for advanced use cases.

import { Queue, InMemoryStorage } from 'knock';

const storage = new InMemoryStorage();
const queue = new Queue(storage, {
  concurrency: 5,
  retryAttempts: 3
});

Storage

Extensible storage interface with in-memory implementation included.

import { Storage } from 'knock-mq';

const storage = new Storage();

For other storage backends (PostgreSQL, Redis, etc.), see storage.examples.md.

Job Priorities

Jobs can be assigned priorities to control processing order:

await queue.add('important-task', data, { priority: 'high' });
await queue.add('normal-task', data, { priority: 'normal' });
await queue.add('background-task', data, { priority: 'low' });

Error Handling

The queue includes comprehensive error handling:

  • Retries: Failed jobs are automatically retried with exponential backoff
  • Circuit Breaker: Prevents cascade failures by temporarily stopping processing
  • Dead Letter Queue: Permanently failed jobs are moved to a dead letter queue
// Access dead letter items
const deadLetterItems = await queue.getDeadLetterItems(10);

Monitoring

Get real-time queue statistics:

const stats = queue.getStats();
console.log({
  queued: stats.queued,
  processing: stats.processing,
  completed: stats.completed,
  failed: stats.failed
});

Performance

Under realistic test conditions:

  • Enqueue Rate: 354 jobs/sec
  • Processing Rate: ~6 jobs/sec (limited by realistic CPU work)
  • P50 Latency: 837ms
  • P99 Latency: 135.9 seconds (under sustained load)
  • Success Rate: 100% with proper error handling

Testing

The package includes a comprehensive testing framework with realistic job scenarios:

npm test

See the tests/ directory for detailed performance testing and monitoring capabilities.

License

MIT

Contributing

Contributions are welcome! Please see the GitHub repository for more information.

Advanced Usage

Custom Storage Backend

import { Queue, Storage } from 'knock-mq';

// Use the built-in in-memory storage
const storage = new Storage();

// Or implement your own storage (PostgreSQL, Redis, etc.)
class CustomStorage implements ExtendedQueueStorage {
  // Implement the storage interface
}

const queue = new Queue({
  name: 'production-queue',
  storage: new CustomStorage(),
  maxRetries: 5,
  backoffBaseMs: 2000,
  maxConcurrent: 20,
  timeoutMs: 60000,
  logger: yourLogger
});