PC Review


Reply
Thread Tools Rate Thread

Async Socket: Rising Thread Count

 
 
Morgan Leppink
Guest
Posts: n/a
 
      10th Dec 2003
Hi all -

We have been developing a complex TCP socket communication
app that is responsible for keeping numerous connections
open to clients on routable IPs. The app receives request
on a non-routable listener socket that marshals
communications between the non-routable netowrk and the
clients out on the routable network.

The app runs as a .NET service in Win2K Server. Async
sockets are being used, with BeginSend(), BeginReceive(),
EndSend(), EndReceive(), etc. Please correct me if I'm
wrong, but our understanding is that these async events
execute on a thread provided by a thread pool created by
the OS.

Operationally, the app is doing exactly what it designed
to do, BUT, the total thread count for the application
gradually rises over time (as displayed by Task Manager).
It starts out at about 18 threads, but after 24 hours it's
up to over 60 threads, and it keeps rising from there.

As expected with an async app, the number of threads does
not have a direct relationship to the number of open
connections. However, it is the marshalling of numerous
TCP messages that seems to make the thread count rise.
The marshalling of messages is when those asynch events
fire, and so I assume that the OS is creating additional
threads from the pool when they are not neccesary for the
operation of the app.

I ALSO assume that we have a bug somewhere. What I am
looking for are likely causes of the OS continuing to
assign additional threads from the pool to my process -
for example, what types of cleanup failures would cause
this? What if EndSend() did not get called properly? The
app is huge, so I would like to narrow it down to the most
likely culprit(s) so we can track this down.

Any other sage advice regarding this type of app would
also be appreciated.

Thanks in advance,

Morgan Leppink
..


 
Reply With Quote
 
 
 
 
Feroze [MSFT]
Guest
Posts: n/a
 
      26th Dec 2003
In order to pinpoint what is happening, you will need to debug this
application. The best way is to attach a debugger of choice to the service,
and break in from time to time to see what the threads are doing. Are they
managed threads executing code in your application ? If so, that might give
you an idea of what code in your application is responsible.

On the other hand, if the Taskmanager is showing a lot of threads, but the
debugger does not show any managed code executing on them, it might be CLR
threads. Then you will have to do some native debugging (using windbg for
example) and see what each of those threads are doing.

Also, do you create threads explicitly, either through ThreadPoo.*
functions, or creating a new Thread object in CLR ?

--
Remove "user" from the email address to reply to the author.

This posting is provided "AS IS" with no warranties, and confers no rights

Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm




"Morgan Leppink" <(E-Mail Removed)> wrote in message
news:01f801c3bf5f$cd83a160$(E-Mail Removed)...
> Hi all -
>
> We have been developing a complex TCP socket communication
> app that is responsible for keeping numerous connections
> open to clients on routable IPs. The app receives request
> on a non-routable listener socket that marshals
> communications between the non-routable netowrk and the
> clients out on the routable network.
>
> The app runs as a .NET service in Win2K Server. Async
> sockets are being used, with BeginSend(), BeginReceive(),
> EndSend(), EndReceive(), etc. Please correct me if I'm
> wrong, but our understanding is that these async events
> execute on a thread provided by a thread pool created by
> the OS.
>
> Operationally, the app is doing exactly what it designed
> to do, BUT, the total thread count for the application
> gradually rises over time (as displayed by Task Manager).
> It starts out at about 18 threads, but after 24 hours it's
> up to over 60 threads, and it keeps rising from there.
>
> As expected with an async app, the number of threads does
> not have a direct relationship to the number of open
> connections. However, it is the marshalling of numerous
> TCP messages that seems to make the thread count rise.
> The marshalling of messages is when those asynch events
> fire, and so I assume that the OS is creating additional
> threads from the pool when they are not neccesary for the
> operation of the app.
>
> I ALSO assume that we have a bug somewhere. What I am
> looking for are likely causes of the OS continuing to
> assign additional threads from the pool to my process -
> for example, what types of cleanup failures would cause
> this? What if EndSend() did not get called properly? The
> app is huge, so I would like to narrow it down to the most
> likely culprit(s) so we can track this down.
>
> Any other sage advice regarding this type of app would
> also be appreciated.
>
> Thanks in advance,
>
> Morgan Leppink
> .
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
writing an async client (sockets/async/thread) asharda@woh.rr.com Microsoft C# .NET 8 17th Mar 2008 10:04 PM
Socket.BeginSend and EndSend causes thread count to runaway Ravi Ambros Wallau Microsoft Dot NET Framework 5 3rd Oct 2005 05:24 PM
Async socket EnzoA Microsoft VC .NET 1 10th May 2005 01:51 PM
Asynchronous Sockets and High Async IO Thread Count =?Utf-8?B?YnJlbmRvbmxhbQ==?= Microsoft Dot NET 2 17th Jan 2005 09:59 PM
Async Socket: Rising Thread Count Morgan Leppink Microsoft Dot NET Framework 1 26th Dec 2003 09:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:17 PM.