Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Max TCP client connections???

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg - 16 Jan 2008 19:16 GMT
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 - 16 Jan 2008 19:33 GMT
> I'm creating a tcp socket connection from the thread in the c#
> threadpool.  Since the default workers thread is 500, sometimes my
[quoted text clipped - 5 lines]
> 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
Ignacio Machin ( .NET/ C# MVP ) - 16 Jan 2008 20:09 GMT
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.

Signature

Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.

> I'm creating a tcp socket connection from the thread in the c#
> threadpool.  Since the default workers thread is 500, sometimes my
[quoted text clipped - 7 lines]
>
> Thanks
Jeroen Mostert - 16 Jan 2008 20:19 GMT
> 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.

Signature

J.

Ignacio Machin ( .NET/ C# MVP ) - 16 Jan 2008 21:41 GMT
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
[quoted text clipped - 5 lines]
> "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.

Signature

Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.

Peter Duniho - 16 Jan 2008 21:54 GMT
> [...]
>  You have a point. It would be much better if the comm. are async and a
[quoted text clipped - 5 lines]
> 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_t
hread/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
Ignacio Machin ( .NET/ C# MVP ) - 17 Jan 2008 13:57 GMT
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.

Signature

Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.

>
>> [...]
[quoted text clipped - 26 lines]
>
> Pete
John - 17 Jan 2008 14:47 GMT
Hi Pete,

Your article showed up fine for me.

It is on the ms newsgroup server as expected.

John

> Or, he could just read the article I posted in reply to his original
> message:
[quoted text clipped - 15 lines]
>
> Pete
Greg - 16 Jan 2008 21:59 GMT
> I'm creating a tcp socket connection from the thread in the c#
> threadpool.  Since the default workers thread is 500, sometimes my
[quoted text clipped - 7 lines]
>
> 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
Chris Mullins [MVP - C#] - 17 Jan 2008 00:42 GMT
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

> I'm creating a tcp socket connection from the thread in the c#
> threadpool.  Since the default workers thread is 500, sometimes my
[quoted text clipped - 7 lines]
>
> Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.