I've hit the need to put a load balancer in front of some Node.js servers and I decided to compare Nginx and Node.js
To do this test I simply spun up an Ec2 Micro (running Ubuntu 14.04) and installed Nginx and Node.js
My nginx.conf file is:
user www-data;
worker_processes 1;
pid /run/nginx.pid;
http {
server {
listen 443 ssl;
return 200 "hello world!";
ssl_certificate /home/bitnami/server.crt;
ssl_certificate_key /home/bitnami/server.key;
}
}
events {
worker_connections 768;
}
And my Node.js code is:
var http = require('https');
var fs = require('fs');
var serverOptions = {
key: fs.readFileSync("/home/bitnami/server.key"),
cert: fs.readFileSync("/home/bitnami/server.crt")
};
http.createServer(serverOptions,function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(443);
console.log('Server running');
I then used another EC2 server (m3.medium due to memory needs) to run wrk with the command
./wrk -t12 -c400 -d30s https://ec2-54-190-184-119.us-west-2.compute.amazonaws.com
The end result was that Nginx could consistently pump through 5x more reqs/second than Node.js (12,748 vs 2,458), while using less memory (both were CPU limited).
My question is, since I'm not exactly great/experienced/knowledgeable in server admin or setup, am I doing something to severely mess up Node.js? And can I confidently draw the conclusion that in this situation, Nginx is absolutely the better choice?