小编Roy*_*hko的帖子

NodeJS集群,它真的需要吗?

我决定要研究用NodeJS服务器处理大量流量的最佳方法是什么,我对2个数字海洋服务器进行了一次小测试,它有1GB RAM/2个CPU无群集服务器代码:

// Include Express
var express = require('express');

// Create a new Express application
var app = express();

// Add a basic route – index page
app.get('/', function (req, res) {
    res.redirect('http://www.google.co.il');
});

// Bind to a port
app.listen(3000);
console.log('Application running');
Run Code Online (Sandbox Code Playgroud)

群集服务器代码:

    // Include the cluster module
var cluster = require('cluster');
// Code to run if we're in the master process
if (cluster.isMaster) {
    // Count the machine's CPUs
    var cpuCount = require('os').cpus().length;

    // Create a worker for each …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express server node-cluster

0
推荐指数
1
解决办法
636
查看次数

标签 统计

express ×1

javascript ×1

node-cluster ×1

node.js ×1

server ×1