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

forkfriend

v0.0.7

Published

dead simple worker child process manager. respawn children. load balance work amongst children.

Downloads

5

Readme

Build Status

forkfriend

dead simple worker process manager. respawn children. load balance work amongst children.

example


var forkfriend = require('friend');
var friend = forkfriend();

// make 3 somefriend.js worker with arguments
friend.add('somefriend.js',['-a',1],3);

// workers for the same file get the same args as the first. 
// multiple calls to add add that many more to the pool
friend.add('somefriend.js')

friend.send('hey one of you work on this');

friend.on('message',function(message,workername,worker){
  // message is the data the child sent.
  // workername === 'somefriend.js'
  // worker instanceof ChildProcess
})

// when you are all done
friend.stop();

api

forkfriend forkfriend(options)

  • options {} [optional]
    • respawnInterval
      • defaults to 500 ms. this is the max speed that new children will be spawned to prevent pegging the cpu on broken workers
    • maxQueue
      • defaults to 100. this is the maximum number of pending messages for workers that should be held while waiting for a functional worker to spawn. after this messages will be dropped but a drop event will be emitted so you application can choose how to handle the issue.
  • returns "friend" an EventEmitter

friend

  • add(script,arguments [optional],num [optional])
  • add(script,num [optional])
    • script is the path to the javascript file you want to fork
    • arguments are passed to fork as argv of your child process
    • the number of children you want to add to the pool. this is the same as calling add multiple times.
  • remove(script)
  • remove(script, num [optional])
  • remove(script,cp ChildProcess [optional])
    • remove a worker from the pool for script
    • if cp is provided this specifc child is removed
    • if num is provided
  • get(script)
    • get an array of the child processes in the pool for script
  • send (message, script [optional])
    • the message to send to one worker of each pool
    • send the message to a worker spawned from "script"
  • stop ()
    • stops the show. kills all child processes so your script can exit cleanly.
  • refork (script, cp ChildProcess [optional])
    • kill and start a specific worker or any in the pool

friend events

  • message (message,script,args,cp ChildProcess)
    • a worker has sent you a message
  • worker (script,args,cp ChildProcess)
    • a new worker has been forked for this script
  • worker-exit (code,script,args,cp ChildProcess)
    • a worker has exited. the friend will try to refork it
  • worker-disconnect (script,args,cp ChildProcess)
    • a child has closed its communication channel with this process. the friend will try to kill it.
  • worker-error (error,script,args,cp ChildProcess)
    • a worker has had an error event, the friend will try to refork it.
  • drop
    • too many messages could not be sent to the workers for this script.

what does a worker look like


process.on('message',function(data){
  // do somthing
  // tell friend about it
  process.send('hey i worked onn '+data);
});

woo hooo.

let me know if this is helpful or if you have any issues.