Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Max TCP client connections???

178 views
Skip to first unread message

Greg

unread,
Jan 16, 2008, 2:16:25 PM1/16/08
to
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

Peter Duniho

unread,
Jan 16, 2008, 2:33:08 PM1/16/08
to

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

Ignacio Machin ( .NET/ C# MVP )

unread,
Jan 16, 2008, 3:09:21 PM1/16/08
to
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.

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Greg" <gca...@gmail.com> wrote in message
news:3b0a40e2-a79d-47b0...@l32g2000hse.googlegroups.com...

Jeroen Mostert

unread,
Jan 16, 2008, 3:19:45 PM1/16/08
to
Ignacio Machin ( .NET/ C# MVP ) wrote:
> 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.

--
J.

Ignacio Machin ( .NET/ C# MVP )

unread,
Jan 16, 2008, 4:41:28 PM1/16/08
to
Hi,


"Jeroen Mostert" <jmos...@xs4all.nl> wrote in message
news:478e66e3$0$85791$e4fe...@news.xs4all.nl...

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.

Peter Duniho

unread,
Jan 16, 2008, 4:54:08 PM1/16/08
to
On Wed, 16 Jan 2008 13:41:28 -0800, Ignacio Machin ( .NET/ C# MVP )
<machin TA <"laceupsolutions.com>"> wrote:

> [...]


> 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/microsoft.public.dotnet.languages.csharp/browse_thread/thread/9d98656262435eb5/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

Greg

unread,
Jan 16, 2008, 4:59:11 PM1/16/08
to

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

Chris Mullins [MVP - C#]

unread,
Jan 16, 2008, 7:42:37 PM1/16/08
to
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.

--
Chris Mullins

"Greg" <gca...@gmail.com> wrote in message
news:3b0a40e2-a79d-47b0...@l32g2000hse.googlegroups.com...

Ignacio Machin ( .NET/ C# MVP )

unread,
Jan 17, 2008, 8:57:52 AM1/17/08
to
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" <NpOeS...@nnowslpianmk.com> wrote in message
news:op.t41ls...@petes-computer.local...

John

unread,
Jan 17, 2008, 9:47:21 AM1/17/08
to
Hi Pete,

Your article showed up fine for me.

It is on the ms newsgroup server as expected.

John

"Peter Duniho" <NpOeS...@nnowslpianmk.com> wrote in message
news:op.t41ls...@petes-computer.local...

0 new messages