↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

600k concurrent websocket connections on AWS using Node.js

The post describes how to squeeze as much capacity as possible out of an AWS EC2 instance at the lowest cost by using concurrent persistent websockets. It says Node.js fits this use case because it is event-driven and non-blocking, then narrows the stack to lighter tools and higher system limits.

Reading notes
#

  • Socket.io was the first choice, but ws was preferred because it is lighter and Socket.io v1.0 no longer works with the cluster module.
  • ws needs manual keepalive handling with ping methods, and AWS load balancer timeouts must stay above the keepalive interval.
  • sticky-session is used so Node.js can run across all CPUs, which is needed for a high connection count.
  • An M3.xlarge EC2 instance is presented as the choice for reaching about 620k connections, with 4 CPUs and 15 GB of memory.
  • At that scale, CPU load stays at 100% and V8 garbage collection becomes the main limiting factor.
  • The recommended stable limit is 600k connections before scaling to another instance.
  • A larger M3.2xlarge instance can reach 800k connections, but cost and Linux network handling become limiting factors.
  • The Node.js flags listed are –nouse-idle-notification, –expose-gc, –max-old-space-size=8192, and –max-new-space-size=2048.
  • The EC2 setup also raises nofile limits to 1000000 and increases fs.file-max, fs.nr_open, netfilterip_conntrack_max, and nf_conntrack_max.
  • The conntrack limit matters because the default value of 65536 would prevent higher connection counts.