Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/protontype/proton-cluster
A clustered starter for Node.js applications
https://github.com/protontype/proton-cluster
cluster nodejs protontype
Last synced: about 5 hours ago
JSON representation
A clustered starter for Node.js applications
- Host: GitHub
- URL: https://github.com/protontype/proton-cluster
- Owner: protontype
- Created: 2018-04-26T00:04:44.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-05-16T12:58:25.000Z (over 6 years ago)
- Last Synced: 2024-11-14T18:55:17.391Z (5 days ago)
- Topics: cluster, nodejs, protontype
- Language: TypeScript
- Size: 11.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
[![npm version](https://badge.fury.io/js/proton-cluster.svg)](https://badge.fury.io/js/proton-cluster)
# A clustered starter for Node.js applications
## Starting workers by CPUs
```typescript
ProtonCluster.startByCPUS(() => {
console.log("Process");
});
```## Starting workers by specified number
```typescript
ProtonCluster.start(8, () => {
console.log("Process");
});
```## Starting Protontype application
```typescript
ProtonCluster.startByCPUS(() => {
new ProtonApplication()
.addRouter(new TasksRouter())
.start();
});
```## Setup events behaviors
Events behaviors should be configured before start clusters.
```typescript
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```typescript
let cluster = ProtonCluster.cluster;cluster.on("online", worker => {
console.log(`Cluster ${worker.process.pid} online`);
});
```