问题:我们在群集模式下启动pm2,并且pm2启动的进程数量与cpu核心一样多,pm2也尝试启动与cpu核心一样多的节点服务器,但问题是它无法启动尽可能多的服务器,因为它们所有尝试并在3000的同一端口上启动,该端口已被第一个节点服务器占用
我们使用nginx并代理它到3000端口.
我们在集群模式下使用pm2,配置如下:
{
"apps" : [{
"script" : "npm",
"instances" : "max",
"cwd":"/home/nginx/my-pwa" ,
"args" : "run start:server:prod",
"exec_mode" : "cluster",
"wait_ready": true,
"kill_timeout" : 4000,
"watch" : true
}]
}
Run Code Online (Sandbox Code Playgroud)
run start:server:prod是我们启动服务器的脚本
我们的快递服务器
var app = require('../src/app');
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
const http = require('http');
server = http.createServer(app);
server.listen(port));
server.on('error', onError);
server.on('listening', onListening);
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? …Run Code Online (Sandbox Code Playgroud) 所以我一直在使用 VSCode,我喜欢它所构建的功能。使用 sublime 我不得不做太多的手动工作。但是 vscode 是 CPU 密集型的,主要是因为文件观察器,我想了解这个文件观察器的作用是什么?在 React 代码中,我们已经有了热重载,我们真的需要这个吗?以及如何一起阻止这一切。
我试图在 vscode 设置 files.watcherExclude 中添加 * 模式来停止 filewatcher 但我不知道它是否真的有效。