node-cluster-promise
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Node Cluster Promise

An easy way to make use of multiple cores.

Why you might need this

  • You are running in an environment where you have access to multiple cores, and do not want to deal with coordinating between individual NodeJS instances
  • Your workload is CPU bound

Why you might not need this

  • In a cloud environment such as kubernetes, you may be better off running many individual NodeJS instances
  • If you are actually limited by network wait, etc.
  • If the overhead of message passing negates any gains you might see

Example Usage

import { ClusterPromise, sleep } from "node-cluster-promise";

const functions = {
  a: async (n: number) => n,
  b: async (str: string) => str,
};

const run = async () => {
  const clusterPromise = new ClusterPromise(functions);

  await clusterPromise.onPrimary(async () => {
    const resA: number = await clusterPromise.run("a", 123);
    const resB: string = await clusterPromise.run("b", "abc");

    console.log(`easy as ${resA} simple as ${resB}`);
  });

  await sleep(1000);

  clusterPromise.shutdown();
};

run();

Package Sidebar

Install

npm i node-cluster-promise

Weekly Downloads

2

Version

0.1.0

License

MIT

Unpacked Size

27.4 kB

Total Files

32

Last publish

Collaborators

  • patches11