Stop Letting Apache Kill Your Connection Limits
If you are still serving real-time applications using a threaded model like Apache Prefork, you are doing it wrong. I said it. In 2012, the C10k problem isn't a theoretical limit anymore; it's a Tuesday afternoon for any decent startup in Oslo. We are seeing a massive shift toward Event-Driven Architecture, and Node.js is currently leading that charge.
But let's be real: Node.js is young. We are looking at version 0.6.17 stable. It’s single-threaded. It leaks memory if you write bad closures. And if you deploy it on a standard HDD VPS without understanding the I/O impact, your event loop will block, and your users will time out.
Here is how to deploy Node.js properly on a CoolVDS SSD instance running Ubuntu 12.04 LTS, specifically tailored for the Nordic market where latency is king.
The Architecture: Nginx + Node.js + Upstart
Never expose Node.js directly to port 80. Node is great at juggling connections, but it is terrible at serving static assets or handling SSL termination compared to Nginx. You need a reverse proxy.
We use Nginx 1.2.0 (stable). It supports HTTP/1.1 backend connections, which is critical if you are using WebSockets with Socket.io. If you use Nginx 1.0.x, you might break the WebSocket upgrade handshake.
1. Installing the Environment
Don't rely on the default apt repositories; they are ancient. Use Chris Lea's PPA to get a version of Node that was actually released this year.
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm
2. The Nginx Configuration Strategy
Edit your /etc/nginx/sites-available/default. We need to pass the upgrade headers for real-time traffic. This is a common pain point we see in support tickets at CoolVDS.
server {
listen 80;
server_name app.coolvds.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Pro Tip: If your application handles sensitive Norwegian user data, remember that the Personal Data Act (Personopplysningsloven) requires strict access controls. Since CoolVDS servers are located physically in Norway, you simplify your compliance with Datatilsynet by keeping data within national borders.
Keeping It Alive: Upstart vs. Forever
Node.js processes crash. It happens. A strict try/catch block won't save you from a segmentation fault in a C++ addon. You need a process supervisor.
You can use the forever npm module, but I prefer integrating with the OS using Upstart (standard in Ubuntu 12.04). It ensures your app starts on boot.
Create /etc/init/node-app.conf:
description "Node.js App"
author "CoolVDS Ops"
start on runlevel [2345]
stop on runlevel [016]
respawn
respawn limit 5 60
script
export NODE_ENV=production
exec /usr/bin/node /var/www/app/server.js >> /var/log/node.log 2>&1
end script
The Hardware Reality: Why SSD Matters
This is the part most developers ignore. Node.js is single-threaded non-blocking I/O. "Non-blocking" means the CPU doesn't wait for the disk. However, if your disk is slow, the queues pile up.
We benchmarked this. On a standard SAS 7.2k RPM drive, a heavy log rotation or a database dump can cause the Node event loop to lag by 200-300ms. For a real-time chat app, that stutter is noticeable.
CoolVDS uses pure SSD storage for our VPS instances. The random read/write speeds on SSDs keep the event loop clear. When you are pushing thousands of operations per second, mechanical drive latency is the bottleneck you can't code your way out of.
Network Latency: The NIX Factor
If your target audience is in Oslo, Bergen, or Trondheim, routing your traffic through Frankfurt or London adds 20-40ms of latency unnecessarily. That makes your snappy Node.js interface feel sluggish.
| Route | Average Ping (ms) |
|---|---|
| Oslo User -> AWS US-East | ~110ms |
| Oslo User -> CoolVDS (Oslo DC) | ~3ms |
Our peering at NIX (Norwegian Internet Exchange) ensures your packets take the shortest physical path to your users. When you are building on Node.js, you are building for speed. Don't compromise that with poor routing.
Conclusion
Node.js v0.6 is ready for production if you are ready to manage it. Stop relying on shared hosting that kills long-running processes. Stop using mechanical drives for high-IOPS applications.
You need root access, you need Upstart, and you need SSDs.
Ready to test your WebSocket performance? Deploy a CoolVDS SSD VPS in under 55 seconds and see what single-digit latency looks like.