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.

Re: how many threads? network programming design .NET by Jon

Jon
Thu Aug 19 06:37:01 CDT 2004

Parahat Melayev <parahat@momenttech.com> wrote:
> 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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: how many threads? network programming design .NET by Patrick

Patrick
Thu Aug 19 06:54:14 CDT 2004

Parahat Melayev wrote:
> 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/default.asp?url=/library/en-us/cpguide/html/cpconioasynchronouscompletion.asp

--
Patrick Philippot - Microsoft MVP
MainSoft Consulting Services
www.mainsoft.fr



Re: how many threads? network programming design .NET by Patrick

Patrick
Thu Aug 19 07:05:55 CDT 2004

See also

http://msdn.microsoft.com/library/?url=/library/en-us/dndotnet/html/progthrepool.asp?frame=true

Please note that there's no direct support for I/O Completion ports in
.Net. However, they're supported internally by some classes.

--
Patrick Philippot - Microsoft MVP
MainSoft Consulting Services
www.mainsoft.fr



Re: how many threads? network programming design .NET by junkmale48

junkmale48
Fri Aug 20 11:38:55 CDT 2004

Have you considered Thread Pools? Which is the recommended way of doing this.

"Patrick Philippot" <patrick.philippot@mainsoft.xx> wrote in message news:<u28#iTehEHA.3988@tk2msftngp13.phx.gbl>...
> See also
>
> http://msdn.microsoft.com/library/?url=/library/en-us/dndotnet/html/progthrepool.asp?frame=true
>
> Please note that there's no direct support for I/O Completion ports in
> .Net. However, they're supported internally by some classes.

Re: how many threads? network programming design .NET by David

David
Sat Aug 21 04:12:30 CDT 2004

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.


"Parahat Melayev" <parahat@momenttech.com> wrote in message
news:%23VGU17dhEHA.1888@TK2MSFTNGP10.phx.gbl...
> 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.
>
>



Re: how many threads? network programming design .NET by Alvin

Alvin
Sat Aug 21 07:24:44 CDT 2004

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.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"David Levine" <noSpamdlevineNNTP2@wi.rr.com> wrote in message
news:edNs971hEHA.3348@TK2MSFTNGP12.phx.gbl...
> 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.
>
>
> "Parahat Melayev" <parahat@momenttech.com> wrote in message
> news:%23VGU17dhEHA.1888@TK2MSFTNGP10.phx.gbl...
>> 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.
>>
>>
>
>



Re: how many threads? network programming design .NET by David

David
Sat Aug 21 10:08:43 CDT 2004


"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:%23tT0Zn3hEHA.596@TK2MSFTNGP11.phx.gbl...
> 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.





Re: how many threads? network programming design .NET by Jon

Jon
Sat Aug 21 10:17:01 CDT 2004

<"Alvin Bruney [MVP]" <vapor at steaming post office>> wrote:
> 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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: how many threads? network programming design .NET by Cor

Cor
Sat Aug 21 10:19:59 CDT 2004

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.




Re: how many threads? network programming design .NET by Richard

Richard
Fri Aug 27 02:15:16 CDT 2004

if i have 1000+ concurrent network connections would threadpooling still
recommended ?

Tom wrote:

> Have you considered Thread Pools? Which is the recommended way of doing this.
>
> "Patrick Philippot" <patrick.philippot@mainsoft.xx> wrote in message news:<u28#iTehEHA.3988@tk2msftngp13.phx.gbl>...
>
>>See also
>>
>>http://msdn.microsoft.com/library/?url=/library/en-us/dndotnet/html/progthrepool.asp?frame=true
>>
>>Please note that there's no direct support for I/O Completion ports in
>>.Net. However, they're supported internally by some classes.

Re: how many threads? network programming design .NET by junkmale48

junkmale48
Mon Sep 20 14:24:15 CDT 2004

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.

Richard Ajian <ajian@NOSPAMbithc.out> wrote in message news:<2p6geqFhaebbU3@uni-berlin.de>...
> if i have 1000+ concurrent network connections would threadpooling still
> recommended ?
>
> Tom wrote:
>
> > Have you considered Thread Pools? Which is the recommended way of doing this.
> >
> > "Patrick Philippot" <patrick.philippot@mainsoft.xx> wrote in message news:<u28#iTehEHA.3988@tk2msftngp13.phx.gbl>...
> >
> >>See also
> >>
> >>http://msdn.microsoft.com/library/?url=/library/en-us/dndotnet/html/progthrepool.asp?frame=true
> >>
> >>Please note that there's no direct support for I/O Completion ports in
> >>.Net. However, they're supported internally by some classes.