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

node-gru

v1.3.1

Published

Gru is a node clustering helper, because he is the master of the minions

Downloads

148

Readme

Gru

Gru is a node clustering helper, because he is the master of the minions

Gru

Is a Fork of https://github.com/hunterloftis/throng with quite a few improvements relating to having a separate startup and running phase.

A single master can control two kinds of workers:

  • Generic workers. Workers who all perform the same task

  • Dedicated workers. Workers who each perform a unique task.

Usage

import { gru } from 'gru'

const numCpus = os.cpus().length

gru({
    workers: process.env.NODE_ENV === 'production' ? numCpus : 1,
    lifetime: Infinity,
    master: async () => {
        // Master initialisation here
    },
    start: async () => {
        // Generic worker initialisation
    },
    dedicatedWorkers: {
        uniqueTask1: () => {
            // Dedicated worker initialization
        },
        uniqueTask2: () => {
            // Dedicated worker initialization
        },
    },
})

API

gru options

workers

Number of generic workers, if 0, starts in process (useful for debugging). Defaults to # of cpu cores

lifetime

ms to keep cluster alive or 'until-killed'

grace

ms grace period after worker SIGTERM (default 5000)

logger

Compatible with Bunyan, Winston and TypeScript-log style logging interfaces, logs gru activity

master

The master process callback.

Optionally can return a promise if there is startup work before worker is considered started.

If the returned promise resolves a value, it will be passed to the workers.

example

gru({
    master: async () => {
        const config = await loadConfig()

        return { config }
    },
    start: ({ masterArgs }) => {
        masterArgs.config // will be the config returned from the master process
    },
})

start

The worker callback.

If the worker returns a promise and it rejects, it signals to gru that the worker failed to start and will not be restarted. Once a worker has started the lifecycle policy will apply (ie workers which crash will be restarted)

dedicatedWorkers

The set of unique worker processes.

example

gru({
    master: async () => {
    },
    start: () => {
    },
    dedicatedWorkers: {
        express: () => {
            // Start an Express server
        },
        fileIngestion: () => {
            // Monitor a directory for zip files to process
        },
    },
})