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.
  • 1
    @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. – joeqwerty Aug 27 '10 at 0:30
  • 1
    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? – evilfred Aug 27 '10 at 0:33
  • 1
    I don't care about the client. – evilfred Aug 27 '10 at 0:36
  • 1
    @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. – joeqwerty Aug 27 '10 at 0:37
  • 1
    I know that. There are only 65k possible server ports per IP. Therefore there is a maximum of 65k active sockets per IP. – evilfred Aug 27 '10 at 0:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy