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

batch-cluster

v13.0.0

Published

Manage a cluster of child processes

Downloads

55,741

Readme

batch-cluster

Efficient, concurrent work via batch-mode command-line tools from within Node.js.

npm version Build status GitHub issues CodeQL Known Vulnerabilities

Many command line tools, like ExifTool, PowerShell, and GraphicsMagick, support running in a "batch mode" that accept a series of discrete commands provided through stdin and results through stdout. As these tools can be fairly large, spinning them up can be expensive (especially on Windows).

This module allows you to run a series of commands, or Tasks, processed by a cluster of these processes.

This module manages both a queue of pending tasks, feeding processes pending tasks when they are idle, as well as monitoring the child processes for errors and crashes. Batch processes are also recycled after processing N tasks or running for N seconds, in an effort to minimize the impact of any potential memory leaks.

As of version 4, retry logic for tasks is a separate concern from this module.

This package powers exiftool-vendored, whose source you can examine as an example consumer.

Installation

Depending on your yarn/npm preference:

$ yarn add batch-cluster
# or
$ npm install --save batch-cluster

Changelog

See CHANGELOG.md.

Usage

The child process must use stdin and stdout for control/response. BatchCluster will ensure a given process is only given one task at a time.

  1. Create a singleton instance of BatchCluster.

    Note the constructor options takes a union type of

  2. The default logger writes warning and error messages to console.warn and console.error. You can change this to your logger by using setLogger or by providing a logger to the BatchCluster constructor.

  3. Implement the Parser class to parse results from your child process.

  4. Construct or extend the Task class with the desired command and the parser you built in the previous step, and submit it to your BatchCluster's enqueueTask method.

See src/test.ts for an example child process. Note that the script is designed to be flaky on order to test BatchCluster's retry and error handling code.

Caution

The default BatchClusterOptions.cleanupChildProcs value of true means that BatchCluster will try to use ps to ensure Node's view of process state are correct, and that errant processes are cleaned up.

If you run this in a docker image based off Alpine or Debian Slim, this won't work properly unless you install the procps package.

See issue #13 for details.