What is the upper limit on the number of open sockets I can have in Windows Server 2003
Asked Answered
Z

3

2

I'm building a chat server with .NET. I have tried opening about 2000 client connections and my Linksys WRT54GL router (with tomato firmware) drops dead each time. The same thing happens when I have several connections open on my Azureus bit-torrent client.

I have three questions:

  1. Is there a limit on the number of open sockets I can have in Windows Server 2003?
  2. Is the Linksys router the problem? If so is there better hardware recommended?
  3. Is there a way to possibly share sockets so that I can handle more open client connections with fewer resources?
Zaffer answered 27/2, 2009 at 11:5 Comment(0)
S
3

AS I've mentioned before, Raymond Chen has good advice on this sort of question: If you have to ask about OS limits, you're probably doing something wrong. The IP protocol only allows for a maximum of 65535 ports and many of these are reserved and not available for general use. I would suggest that your messaging protocols need to be thought out in more detail so that OS limits are not an issue. I'm sure there are many good resources describing such systems, and there are certainly people here that would have good ideas about it.

EDIT: I'm going to put some thoughts about implementing a scalable chat server.

First off, designate a single port on the server for clients to communicate through. Whenever a client needs to update the chat state (a new user message for example) do the following:

create message packet
open port to server
send packet
close port

The server then does the following:

connection request received
get packet
close connection
process packet
for each client that requires updating
  open connection to clients
  send update packet
  close connection

When a new chat session is started, the client starting the session sends a 'new session' message to the server with the clients user details and IP address for responses. The server creates a new chat session and responds with the session ID. The client then sends packets containing the messages the user types, the server processes them and forwards the message to other clients in the same session. When a client leaves the chat, it sends a 'end session' message to the server. The server removes the client from the session and destroys the session when there are no more clients in the session.

Hope that gets you thinking.

Shoa answered 27/2, 2009 at 11:14 Comment(10)
Skizz: thanks, but i cannot locate the relevant article from the link you provided. if i can get up to 50k from one box it is fine, can you point me to one of these good resources you have used yourself. thanksZaffer
The site talks a lot about system stuff and occasionally there's a comment about system limits which is usually answered with the above statement. If you need 50k connections, what's going to happen the day there's 50001 required? You need to use one connection and make it handle 50k chats.Shoa
opening & closing connections per message sent? how well will that scale? I've been doing some reading i understand that if all my communications are async i can have most sockets sleeping & waking when there is data available to process via a write/read end. your thoughts.Zaffer
To be honest, I'm no expert on this sort of stuff. But I'm certain the one-socket-per-chat method is flawed. How does Hotmail's IM do it? They must have far more than 50K chats at once.Shoa
Actually, it just occurred to me that the IM system can work as a peer-to-peer system where the server is used to set-up the p2p sessions, i.e. tell clients the IP address of other clients in the same session.Shoa
Most Chat clients do have an active established connection with the server, I know this for Gtalk, they scale based on multiple serversLucienlucienne
Yeah, I was thinking it could scale using multiple servers, a master for initial set up which then delegates to the least loaded chat server.Shoa
I receive all connection requests via a master server, then based on client_id i can redirect. Say svr1 handles client_id 1 to 10000, then svr2 handles client_id 10001 to 20000 etc. If i can up the number of client connections per box, i can handle more with less. That's why i'm seeking guidance.Zaffer
skizz: your example is flawed. The server should not open connections to the users since typically they are behind firewalls. Thats why it IS relevant to keep connections open in an IM client (or to use UDP)Limiting
@Toad: Thanks, I was having that doubt while implementing a protocol over UDP which requires to keep pinging to keep the firewall ports open. What I was thinking that could work was to implement some multiplexing which packs many-port messages to a single-port output pointing to the actual service in another computer, probably deflating the packet groups in order to maximize output speed.Scudo
Z
3

i have found some answers to this that i feel i should share:

Windows 2003 server has a limit on the number of ports that may be used. but this is configurable via a registry tweak to change the MaxUSerPort setting from 5000 to say, 64k( max).

Exploring further, i realize that the 64k port restriction is actually per IP address, hence a single server can easily attain much more ports, and hence TCP connections by either installing multiple network cards, or binding more than one IP address to a network card. that way, you can scale your system to handle n x 64k ports.

Zaffer answered 11/3, 2009 at 13:37 Comment(0)
M
1

Had for days a problem with the available sockets on my Window 7 machine. After reading some articles about socket leaks in Win 7, I applied a Windows patch - nothing changed.

Below there is an article describing windows connection problems in great detail: http://technet.microsoft.com/en-us/magazine/2007.12.network.aspx

For me it worked the following:

  1. Open Regedit
    • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters: Create TcpNumConnections, REG_DWORD, decimal value 500 (this can be set according to your needs); EnableConnectionRateLimiting, REG_DWORD, value 0;
    • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip: Create MaxUserPort, REG_DWORD, decimal value 65534
  2. Restart Windows
Mckeon answered 20/5, 2013 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.