我决定要研究用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)