educative.io

How do we assume a modern web server can handle 50k concurrent connections?

How many chat servers we need? Let’s plan for 500 million connections at any time. Assuming a modern server can handle 50K concurrent connections at any time, we would need 10K such servers.

Referring to this paragraph. Could you explain why/how a modern server can handle 50k concurrent connections? Where did we get this number? Thanks.

3 Likes

A good way to estimate is - assume each connection takes up 1MB of RAM - then 50,000 connections would take up 50 GB or RAM. So you are bound by how much RAM a modern server has.

You can refer a nice article here:

2 Likes

This was mostly likely the case with WebSocket. Web-socket use TCP and port number is of 16 bit, so technically server can open 2^16 connection ~ 65k ( this is my assumption as the best way to handle it using WebSocket and not other way, but I can be wrong)

Thanks for asking this question, this is seriously something I have not been able to wrap my head around. Whatever I google generally tends to answer it in a TCP connections language, but modern web servers working on HTTP is there a difference.
What exactly is the theory behind this and wouldn’t this be a great way to benchmark different languages/frameworks for server side development ? Still looking for a better explanation.

@Umesh_Awasthi, that is not correct. A connection is established between 2 pairs of IPs and ports, say <source_IP:source_port> and <dest_IP:dest_port>. Typically destination port is fixed, for example 80 (HTTP). The source IP can open 2^16 simultaneous connections to <dest_IP:80>, from <source_IP:10000>, <source_IP:10001> etc (the source port is usually randomly picked from a high range), and excluding other limitations another source IP could open the same amount of connections.

The maximum limit of connections comes from the maximum number of file descriptors available to the process, most commonly. Then, there will be other limitations, such as the available memory to handle the connections internally (how much memory does your process use per connection?).

@sim, HTTP works on top of TCP/IP.

See: https://en.wikipedia.org/wiki/OSI_model

IP is layer 3, TCP is layer 4, HTTP is layer 7.

Check also: https://en.wikipedia.org/wiki/Internet_protocol_suite

I think we are talking about the same thing…what I am explaining was the maximum theoretical limit per client

If you not consider HTTP2 or similar things…the HTTP is a client centrist protocol which means client will initiate the request but for something like chat server that will not work or will be consuming a lot of resources.

Thanks for asking this question. It would be really nice if Educative responded to questions like this to explain their line of thinking.