tags:

views:

606

answers:

3

Say if I was to get shared, virtual or dedicated hosting, I read somewhere a server/machine can only handle 64,000 TCP connections at one time, is this true? How many could any type of hosting handle regardless of bandwidth? I'm assuming HTTP works over TCP.

Would this mean only 64,000 users could connect to the website, and if I wanted to serve more I'd have to move to a web farm?

+1  A: 

Note that HTTP doesn't typically keep TCP connections open for any longer than it takes to transmit the page to the client; and it usually takes much more time for the user to read a web page than it takes to download the page... while the user is viewing the page, he adds no load to the server at all.

So the number of people that can be simultaneously viewing your web site is much larger than the number of TCP connections that it can simultaneously serve.

Jeremy Friesner
+1  A: 

The port number is a 16-bit unsigned integer, so 65536 is a hard limit on the maximum number of TCP/IP connections. This varies from system to system, but a more realistic number is "several thousand". For web sites, the actual number of sessions can be much greater than the maximum number of simultaneous sockets because a web browser disconnects after transfering the data and reconnects later as necessary.

binarycoder
Your system can have a 65535 listening ports (0 not allowed). However, a TCP/IP connection is considered unique by the combination of the source IP and source port and destination IP and destination port. A web server can handle a thousand concurrent connections on port 80 as long as they are coming from different clients or from different ports on the same client.
Variable Length Coder
<on port 80> To clarify, once the connection is accept'ed, a port other than 80 will be assigned from a dynamic range of ports and associated with the newly accepted connection. So this will still be subject to port limitations even though all of the connections come in on the same port 80. On Windows 2008, for example, the default dynamic port range is 49152 to 65535.
binarycoder
This is a common misunderstanding of what accept() does. There is no way to change the port of an established TCP stream. On the server side, it will always be at port 80. A server can handle multiple connections on a single port at the same time, there is no need to unload them to other ports.Go ahead and type 'netstat' on your machine and see which remote ports it's connected to stackoverflow.com on.
Variable Length Coder
Variable -- D'oh, you're right. Its obvious now that I think about it. I'll leave that comment here in case someone else has the same misconception!
binarycoder
+2  A: 

This question is a fairly difficult one. There is no real software limitation on the number of active connections you can have (obviously some OS's are more limited than others). The problem starts to become one of resources. If you use 1MB of RAM per connection, at 64K connections you're using 64GB of RAM. If each client needs to read a file, your disk (or storage array) is getting hammered. If your server needs to fork one process per connection, you now have 64K processes running on your machine and it will spend all of its time context switching.

The C10K problem page has a very good discussion of this issue.

Variable Length Coder