typescript导入cluster与hapi实现多核多线程http服务器代码

代码语言:typescript

所属分类:

代码描述:typescript导入cluster与hapi实现多核多线程http服务器代码

代码标签: hapi 多核 线程 http 服务器

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

import * as cluster from 'cluster';
import { cpus } from 'os';
import * as Hapi from 'hapi';

const numCPUs = cpus().length;

if (cluster.isMaster) {
  for (var i = 0; i < numCPUs; i++) {
    cluster.fork();
  }
  cluster.on('exit', (worker, code, signal) => {
    console.log(`worker ${worker.process.pid} died`);
  });
} else {
    const server = new Ha.........完整代码请登录后点击上方下载按钮下载查看

网友评论0