I would like to have as many connections (single connections from many different clients) as humanly possible in a server running on Windows Server 2008, in order to support a Comet-style application. The application is written in C#. The connections will not be chatty, they just need to be open (and stay open). Buying boatloads of memory and fast CPUs are not a problem.
As far as I can tell, I will be limited to 65k simultaneous open connections per NIC - the maximum number of ports. Is this accurate? Or can I go beyond 65k connections / NIC somehow? It seems like there are server products for Linux at least that support hundreds of thousands of connections. How do they do this?
-
You can go well beyond 65k connections; as you can have multiple connections per port (once accepted, the listener can connect to another client). One end or the other does have to have some difference, usually the client picks a random port. Windows is by default limited to a few more than 3000 of these random ports; so your typical client will max out around that. It's possible to configure the client differently however, and many *nix are limited to many more than Windows.
There's a registry setting limiting the maximum number of connections to 16 million. But there are other more practical problems that will usually limit you to less (you can change the registry value).
- Windows takes up about 1KB of RAM per connection (That's ~16GB for 16M connections); and your app will also have to keep track of it's active connections somehow (more memory).
- Windows will also check for non-responsive connections ever 2 hours. At 16M connections this is about every 0.5 ms; it would take up significant bandwidth just doing those checks.
evilfred : I don't get it. I know how to modify windows to allow for more ephemeral ports. In a perfect world there are 65k possible ephemeral ("random") ports. So there is a max of 65k that can be SIMULTANEOUSLY connected, no? I also don't get why you're talking about a client "maxing out". Each client will only have one connection to the server.joeqwerty : @evilfred: ephemeral ports are for outgoing TCP connections, meaning that a client machine will use an ephemeral port when it connects to your web server on port 80. As Chris S stated, once that session is established the web server is able to establish another connection on port 80 from a different client. Also, I think he mentioned the client ephemeral port limit in trying to be exhaustive in his answer, this client ephemeral port limit is not your concern, it's the clients concern. @Chris S: I hope I'm not mis-stating what you meant in your answer.evilfred : So there is no real limit on the number of inbound connections that a server can support on a single IP? How does the server know where to send data it receives from a client if the destination port is shared?Chris S : @evilfred, to start with the first 1024 ports are reserved for elevated privilege only; but Windows will not (by default) use a port over port 5000; plus the OS uses a few itself; so on a typical Windows computer the user gets ~3700, and they'll probably want to use a several dozen of those for other things (like browsing the web, chat client, whatever). So realistically you can rely on 3k-ish; with the possibility of more. This is for the client, not the server.evilfred : I don't care about the client.Chris S : @evilfred, The inbound connections are realistically limited to 3,000-ish per client; and a few million total connections; with the right hardware, tuning, and network; possibly 10 to 20 million connections. I don't know your application, so I'm just trying to get both ends of the equation. The server would know where data is going based on the ServerIP,ServerPort,ClientIP,ClientPort set; each connection must be unique.joeqwerty : @evilfred: Each TCP session is "managed" via what is called a 4-tuple, which is client ip|client port<>server ip|server port. That's how the server manages traffic between each session on a "shared" port, such as port 80 on a web server.evilfred : I know that. There are only 65k possible server ports per IP. Therefore there is a maximum of 65k active sockets per IP.Chris S : @evilfred, No. The server can connect it's one IP, and one Port, to many Client IPs.evilfred : Ok. Thank you. So I could have 2 simultaneously open TCP sesions: <1.1.1.1:777:2.2.2.2:888> and <3.3.3.3:777:2.2.2.2:888>. Even though they both have the same server IP + server port, the server is able to distinguish them based on the source?joeqwerty : @evilfred: You're kind of missing the point. The 65k port "limit" you're referring to is applicable to outgoing TCP sessions when a computer is acting as a client (Chris S has explained the real world availablility of outgoing ports on the client side). On your web server the server uses only one port, which is port 80. The number of incoming client connections to port 80 on the web server is limited to the amount of CPU and memory on the server and is dependent on the implementation of the TCP\IP stack on the server.Chris S : @evilfred; if the 2.2.2.2:888 is the server; yes; that's exactly how they're kept track of.joeqwerty : @evilfred: See my comment about the 4-tuple. This is how the server manages and maintains each TCP session. The 4-tuple is what makes each session unique.joeqwerty : BTW, I love these kinds of discussions. +1 to evilfred for posting a good question.From Chris S
0 comments:
Post a Comment