Max TCP client connections???

G

Greg

I'm creating a tcp socket connection from the thread in the c#
threadpool. Since the default workers thread is 500, sometimes my
program tries to open up 500 different tcp socket connections and the
connection fails after it reaches certain number of opened tcp
connection. I guess it reached the max number of tcp connection
available in the operating system. I have Professional Windows XP
2000. So what is the max simultaneous tcp connection in this
operating system? Or how can I find out the how many tcp connections
are available?



Thanks
 
P

Peter Duniho

I'm creating a tcp socket connection from the thread in the c#
threadpool. Since the default workers thread is 500, sometimes my
program tries to open up 500 different tcp socket connections and the
connection fails after it reaches certain number of opened tcp
connection. I guess it reached the max number of tcp connection
available in the operating system. I have Professional Windows XP
2000. So what is the max simultaneous tcp connection in this
operating system? Or how can I find out the how many tcp connections
are available?

I may be wrong, but I wasn't aware of any arbitrary maximum number of
connections possible, even on a non-server version of Windows.

Your message _seems_ to be saying that you are using a thread pool thread
to create each connection. If by that you mean that each connection has
its own thread pool thread, then it seems likely to me that you're
actually running out of threads, not connections.

If you want to host a large number of multiple connections, you need to
avoid a "one thread per connection" implementation. That technique will
always unnecessarily limit the number of connections you can have at once,
and performance will suffer even before you reach that limit.

Instead, look at the asynchronous API on the Socket class (or TcpClient
and Stream if that's what you're using), where you call methods with
"Begin" and "End" as part of the names. For example,
Socket.BeginConnect() and Socket.BeginRead(). These methods provide a
much more scalable and efficient way of managing multiple connections with
the same parallelism that multiple threads would give you, but without the
limitations. (In fact they do use threads themselves, but in a much more
efficient way than dedicating one to each connection).

If I've misunderstood your architecture, then you should probably post a
concise-but-complete example of code that illustrates what you _are_
doing. It's too easy to misunderstand a human language description of an
implementation, but code is code. :)

Pete
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


You can either be running out of TCP connections (which I do not think ) or
of threads (which I think is the cause of your problem). Try to increase the
number of threads.
 
J

Jeroen Mostert

Ignacio said:
You can either be running out of TCP connections (which I do not think ) or
of threads (which I think is the cause of your problem). Try to increase the
number of threads.
No, please don't follow this advice. If you're hitting the thread pool
default maximum of 500 worker threads, you're doing something wrong. That's
just not a reasonable amount of threads to use. "500" is as good as
"infinity" here, unless you have a machine with, say, 100 processors, and
memory to burn.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Jeroen Mostert said:
No, please don't follow this advice. If you're hitting the thread pool
default maximum of 500 worker threads, you're doing something wrong.
That's just not a reasonable amount of threads to use. "500" is as good as
"infinity" here, unless you have a machine with, say, 100 processors, and
memory to burn.

You have a point. It would be much better if the comm. are async and a
thread can handle more than one connection.
OP:
Do a search of how to do a high performance TCP server. I'm pretty sure you
will find something about how to handle 1K connections without killnig the
machine.
 
P

Peter Duniho

[...]
You have a point. It would be much better if the comm. are async and a
thread can handle more than one connection.
OP:
Do a search of how to do a high performance TCP server. I'm pretty sure
you
will find something about how to handle 1K connections without killnig
the
machine.

Or, he could just read the article I posted in reply to his original
message:
<http://groups.google.com/group/micr...56262435eb5/c6228fc1e8ade078#c6228fc1e8ade078>

I'm curious: that article has not shown up on my news server yet. I
suspect it never will. Obviously it was sent, since Google has it. Are
others not receiving it either? I could repost it, but since the main
point for doing so would be to ensure it's in the archive, and since it's
obviously already in the archive, I think there's probably no point in me
doing that.

The even shorter version of my relatively short reply is: use the
asynchronous methods on the Socket or TcpClient and Stream classes, as
appropriate. Those methods have names that all start with either "Begin"
or "End". Using that mechanism, handling a thousand connections would be
trivial; hundreds of thousands of connections should be possible, assuming
no other limitations.

Pete
 
G

Greg

I'm creating a tcp socket connection from the thread in the c#
threadpool. Since the default workers thread is 500, sometimes my
program tries to open up 500 different tcp socket connections and the
connection fails after it reaches certain number of opened tcp
connection. I guess it reached the max number of tcp connection
available in the operating system. I have Professional Windows XP
2000. So what is the max simultaneous tcp connection in this
operating system? Or how can I find out the how many tcp connections
are available?

Thanks

I'd like to thank everyone for a quick response and for sharing their
insight.
I just stumbled across this: http://forum.emule-project.net/lofiversion/index.php/t56016.html

It describes that XP SP1 has an unlimited of TCP client connection
requests whereas SP2 only allows 10 per second.
I've implemented a counter that increments on the request, and
decrements when connected. If the counter should reach 10, that thread
sleeps for a maximum of 1000ms waiting for a valid connection or
timeout. Whichever comes first.
It seems to work fine now, but will be running more test to confirm
these findings. Stay tuned.

Thanks again.

Greg
 
C

Chris Mullins [MVP - C#]

The magic setting you're looking for is "MaxUserPort". You can google this,
then make the appropiate registry change.

Thie value is typically set at 5000, and if you want lots and lots of client
connections then you need to bump the value up.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi Peter,

I never got it, and I have the configuration to get like 1000 messages.

I have notices the same thing with some of my posts though.

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Peter Duniho said:
[...]
You have a point. It would be much better if the comm. are async and a
thread can handle more than one connection.
OP:
Do a search of how to do a high performance TCP server. I'm pretty sure
you
will find something about how to handle 1K connections without killnig
the
machine.

Or, he could just read the article I posted in reply to his original
message:
<http://groups.google.com/group/micr...56262435eb5/c6228fc1e8ade078#c6228fc1e8ade078>

I'm curious: that article has not shown up on my news server yet. I
suspect it never will. Obviously it was sent, since Google has it. Are
others not receiving it either? I could repost it, but since the main
point for doing so would be to ensure it's in the archive, and since it's
obviously already in the archive, I think there's probably no point in me
doing that.

The even shorter version of my relatively short reply is: use the
asynchronous methods on the Socket or TcpClient and Stream classes, as
appropriate. Those methods have names that all start with either "Begin"
or "End". Using that mechanism, handling a thousand connections would be
trivial; hundreds of thousands of connections should be possible, assuming
no other limitations.

Pete
 
J

John

Hi Pete,

Your article showed up fine for me.

It is on the ms newsgroup server as expected.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top