We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在nodejs中,cluster子进程因为某种原因disconnect之后,会处理完所有的数据之后,自动被master重启。
import { Burn } from './core'; import * as cluster from 'cluster'; import * as os from 'os'; import { EventEmitter } from 'events'; export default class BurnCluster extends EventEmitter { constructor() { super(); } forkWorkers() { const numCPUs = os.cpus().length; if (cluster.isMaster) { // Fork workers. console.log(`master进程#${process.pid}`) for (let i = 0; i < numCPUs; i++) { cluster.fork(); } cluster.on('fork', function (worker) { console.log('worker ' + worker.process.pid + ' start'); worker.on('message', (msg) => { console.log(msg + 'from ' + worker.process.pid) }) }) cluster.on('online', function (worker) { worker.disconnect(); }) cluster.on('exit', function (worker, code, signal) { console.log('worker ' + worker.process.pid + ' died'); // cluster.fork(); }); cluster.on('disconnect', function (worker) { if (worker.isDead) { console.log('工作进程 #' + worker.id + ' 已经死亡'); } console.log('工作进程 #' + worker.id + ' 断开了连接'); }) cluster.on('listening', (worker, address) => { }); } else { const app = new Burn; app.run(); // process.on('message', function (msg) { // console.log('3:', msg); // }); // (<any>process).send('你好'); } } startCluster() { this.forkWorkers(); } }
worker进程的master被杀死之后,worker都会立即自杀。
在cluster master中,childprocess收到disconnect后,不会自动被集群重启。
需要认为的手动退出和重启。
在master死后,childprocess也不会自动杀死自己,而是变成孤儿进程。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
cluster中
在nodejs中,cluster子进程因为某种原因disconnect之后,会处理完所有的数据之后,自动被master重启。
worker进程的master被杀死之后,worker都会立即自杀。
childprocess中
在cluster master中,childprocess收到disconnect后,不会自动被集群重启。
需要认为的手动退出和重启。
在master死后,childprocess也不会自动杀死自己,而是变成孤儿进程。
The text was updated successfully, but these errors were encountered: