Node.js on multi-core machines

前端 未结 15 1487
猫巷女王i
猫巷女王i 2020-11-22 07:46

Node.js looks interesting, BUT I must miss something - isn\'t Node.js tuned only to run on a single process and thread?

Then how does it scale for m

15条回答
  •  没有蜡笔的小新
    2020-11-22 08:31

    As mentioned above, Cluster will scale and load-balance your app across all cores.

    adding something like

    cluster.on('exit', function () {
      cluster.fork();
    });
    

    Will restart any failing workers.

    These days, a lot of people also prefer PM2, which handles the clustering for you and also provides some cool monitoring features.

    Then, add Nginx or HAProxy in front of several machines running with clustering and you have multiple levels of failover and a much higher load capacity.

提交回复
热议问题