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

1.0.3 • Public • Published

npm version

A clustered starter for Node.js applications

Starting workers by CPUs

ProtonCluster.startByCPUS(() => {
   console.log("Process");
});

Starting workers by specified number

ProtonCluster.start(8, () => {
   console.log("Process");
});

Starting Protontype application

ProtonCluster.startByCPUS(() => {
   new ProtonApplication()
   .addRouter(new TasksRouter())
   .start();
});

Setup events behaviors

Events behaviors should be configured before start clusters.

ProtonCluster.onOnline(worker => {
    console.log(`I am Online Event`);
});
 
ProtonCluster.onExit(worker => {
    console.log(`I am Exit Event`);
});
 
ProtonCluster.onDisconnect(worker => {
    console.log(`I am Disconnect Event`);
});
 
ProtonCluster.onMessage(worker => {
    console.log(`I am Message Event`);
});
 
ProtonCluster.startByCPUS(() => {
    console.log("Test");
});

Cluster instance

You can access native Node.js cluster instance

let cluster = ProtonCluster.cluster;
 
cluster.on("online", worker => {
    console.log(`Cluster ${worker.process.pid} online`);
});

Package Sidebar

Install

npm i proton-cluster

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

15.1 kB

Total Files

16

Last publish

Collaborators

  • linck