Linux – How to scale up a web server supporting long polling

high-availabilitylinuxload balancingtomcatUbuntu

I am planing to add more web application servers to support increasing clients, deploying HAproxy and Keepalived for load balancing and High availability.

My server usage has the following characteristic:

  1. Jobs are not CPU intensive. Message are JSON text less than 100
    character.
  2. Users will send message to server through Client device Y. Usually 4-5 messages per day
  3. Client devices X keep waiting message from server. If message is available at server, client device X must be able to get it within 2 seconds. Otherwise, this message is outdated.

For this reason,

  1. Client devices X is using long polling HTTP connection in order to be responsive. Each connection will last for 5 seconds and reconnect.
  2. Client devices X and Client devices Y are connected to same server, so X and Y can send message easily

Question

If there are over 60,000 Client devices X connecting to server, my load balancer or router will be running out of TCP port. What is the best way to scale up for , say, 20,000 users?

My server is running on Ubuntu server, using tomcat and Java Servlet.

Best Answer

I don't think your 60k clients are the actual problem. You will more likely have problem with not enough file descriptors, but that should be easy to fix as part of OS configuration.

Here's why connections will not be your problem. Each connection is characterised by its source ip address, source port, destination ip address and destination port. Inside the network stack this quadruple is used to match packets to file descriptors(each file descriptor represents a connection). Your server has fixed destination ip address and destination port (your server is destination for their client) but source ip address and source port are variable. Port is a 16bit number therefore maximum number of connections from one client is 64K. IPv4 address is a 32 bit number which gives you 4,294,967,296 possible source addresses. Doing some basic maths, your server could have 64K * 4,294,967,296 connections mapped to a single source ip and port.

This is why you will more likely have problem with maximum number of open file descriptors then the number of clients.

Related Topic