how many threads? network programming design .NET

  • Thread starter Thread starter Parahat Melayev
  • Start date Start date
P

Parahat Melayev

Hi

I am programming a multi-threaded asyncronous server with .NET

But when systems thread count reaches to 1350 system can't respond.

Simply my design is creating a Reading Thread after every Accept.
And creating a Writing Thread when server sends data.

Can you share your experience with me on Network Programming and
Multi-Threading.
 
Parahat Melayev said:
I am programming a multi-threaded asyncronous server with .NET

But when systems thread count reaches to 1350 system can't respond.

Simply my design is creating a Reading Thread after every Accept.
And creating a Writing Thread when server sends data.

Can you share your experience with me on Network Programming and
Multi-Threading.

Rather than create two threads for every network connection, use the
asynchronous calls (BeginRead etc) so that you only end up with a few
threads at a time, rather than loads of threads actively blocking on
network access.
 
Parahat said:
I am programming a multi-threaded asyncronous server with .NET

But when systems thread count reaches to 1350 system can't respond.

The more threads running on your system, the lower the ratio production
time vs. context switching time for the CPU. A good server application
only runs a limited number of threads at a time Quickly serving a few
requests is much better that very slowly serving a big number of
requests.

Consider using I/O Completion ports and / or thread pooling to manage
this. See

http://msdn.microsoft.com/library/d...pguide/html/cpconioasynchronouscompletion.asp
 
You are probably running out of virtual address space. .NET maps each thread
to an underlying operating system thread, and allocates 1M of virtual
address space for each one. By default each app gets a max of 2G of virtual
address space from the operating system, so you are probably bumping into
this limit.

As others have mentioned, no one writes code that uses so many threads, most
of which are blocked waiting on other operations to complete. Use a
threadpool, either the .NET pool (recommended) or roll your own.
 
That's my gripe with .net. They made it so easy to use threads, everybody is
doing it some without the slightest clue of what is going. at least in C++
it was difficult enough that it scared people away from using it so it was
left to those few people brave and knowledgable.
 
Alvin Bruney said:
That's my gripe with .net. They made it so easy to use threads, everybody is
doing it some without the slightest clue of what is going. at least in C++
it was difficult enough that it scared people away from using it so it was
left to those few people brave and knowledgable.

Hah. I'm not sure that situation was any better! And I've written a lot of
win32 threaded code.

It's actually an interesting question; how much should a developer new to
..net and windows have to know about the platform it's running on, especially
when .net promises to hide those details? Or is it the developer's fault for
believing the promise?

My take is that complete platform neutrality is more of a pie-in-the-sky
goal that may one day be reached, but the current state-of-the-art is that
there are lots of fussy details that have to be dealt with, and threading
and execution-related issues are high on the list of items like that. IOW,
the more you know the better off you are.
 
That's my gripe with .net. They made it so easy to use threads,
everybody is doing it some without the slightest clue of what is
going. at least in C++ it was difficult enough that it scared people
away from using it so it was left to those few people brave and
knowledgable.

I don't think keeping people away from threads in the first place is
the right solution though. They're fundamentally necessary to almost
any non-trivial application other than batch processing, IMO.
 
For those who are interested in Threading and VBNet a message in the
language.vb newsgoup from Jason Cooke

[ANN] August 24, "Threading with Visual Basic .NET" chat

Do you have questions about how to create multi-threaded applications? Or do
you wonder about what those threads are actually doing? Then join members of
the Visual Basic team as they answer your questions about using threading
with Visual Basic .NET.

Date:
August 24, 2004
1:00 - 2:00 P.M. Pacific time
4:00 - 5:00 P.M. Eastern time
20:00 - 21:00 GMT
(For a list of local time zones relative to GMT, please see
http://msdn.microsoft.com/chats/timezones.asp.)

Outlook Reminder:
http://msdn.microsoft.com/chats/outlook_reminders/MSDN_TVBNET_Aug2404.ics

Location:
http://msdn.microsoft.com/chats (then click the name of the chat to enter
the chat room)

For more information about Visual Basic .NET, see
http://msdn.microsoft.com/vbasic/
To see a list of upcoming chats or set a reminder for this chat, see
http://msdn.microsoft.com/chats.
For archives of previous chats, see
http://msdn.microsoft.com/chats/recent.asp.

Thanks!
Jason Cooke
VB.NET Team

========
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.
(c) 2004 Microsoft Corporation. All rights reserved.
 
if i have 1000+ concurrent network connections would threadpooling still
recommended ?
 
This is the exact situation that you would want to use thread pooling
for. The computer can only do so much you don't want it bogged down
with the context switchs for over 1000 idle thread.
 
Back
Top