Web Images Videos Maps News Groups Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
How Many Threads Do I Get?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
SnapDive  
View profile  
 More options Oct 28, 1:08 am
Newsgroups: microsoft.public.dotnet.framework
From: SnapDive <SnapD...@community.nospam>
Date: Tue, 27 Oct 2009 10:08:03 -0400
Local: Wed, Oct 28 2009 1:08 am
Subject: How Many Threads Do I Get?

I have an app that uses the stock .NET 3.5 thread pool to spawn
background workers which do some work, make an async WCF call (which
does some LINQ to SQL), and then quit.

If this was an ASP.NET app I think I would be limited to 20 or 25
threads to get things like this done before I had to use a custom
thread pool.

If I am doing the above in my own Win32 service (console app), does
the same limit apply? The hardware is a dual processor system on
Windows Server 2003.

Thanks.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gregory A. Beamer  
View profile  
 More options Oct 28, 2:08 am
Newsgroups: microsoft.public.dotnet.framework
From: "Gregory A. Beamer" <NoSpamMgbwo...@comcast.netNoSpamM>
Date: Tue, 27 Oct 2009 08:08:02 -0700
Local: Wed, Oct 28 2009 2:08 am
Subject: Re: How Many Threads Do I Get?
SnapDive <SnapD...@community.nospam> wrote in
news:f5vde5hns63mkdiefl2dhgojrjnvmv80ce@4ax.com:

> I have an app that uses the stock .NET 3.5 thread pool to spawn
> background workers which do some work, make an async WCF call (which
> does some LINQ to SQL), and then quit.

> If this was an ASP.NET app I think I would be limited to 20 or 25
> threads to get things like this done before I had to use a custom
> thread pool.

> If I am doing the above in my own Win32 service (console app), does
> the same limit apply? The hardware is a dual processor system on
> Windows Server 2003.

I am not sure what the maximum limit is with windows services, but it is
fairly easy to set up a thread pool using a ThreadPool object and set the
Max threads to whatever you need to ensure your work is done properly. It
would also be safer if you see this service doing more work over time, as
you can spin it up with additional threads when it fails to scale.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
|      Think outside the box!             |
*******************************************


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott M.  
View profile  
 More options Oct 28, 2:47 am
Newsgroups: microsoft.public.dotnet.framework
From: "Scott M." <s-...@nospam.nospam>
Date: Tue, 27 Oct 2009 11:47:44 -0400
Local: Wed, Oct 28 2009 2:47 am
Subject: Re: How Many Threads Do I Get?

"SnapDive" <SnapD...@community.nospam> wrote in message

news:f5vde5hns63mkdiefl2dhgojrjnvmv80ce@4ax.com...

> I have an app that uses the stock .NET 3.5 thread pool to spawn
> background workers which do some work, make an async WCF call (which
> does some LINQ to SQL), and then quit.

> If this was an ASP.NET app I think I would be limited to 20 or 25
> threads to get things like this done before I had to use a custom
> thread pool.

> If I am doing the above in my own Win32 service (console app), does
> the same limit apply? The hardware is a dual processor system on
> Windows Server 2003.

> Thanks.

Will this help:

  Private Sub Procedure2()
    Dim nl As String = Environment.NewLine

    'Get a reference to the currently running thread...
    Dim currentThread As Thread = Thread.CurrentThread

    'Set up some placeholders for the GetMaxThreads call
    Dim workerThreads As Integer
    Dim portThreads As Integer
    ThreadPool.GetMaxThreads(workerThreads, portThreads)

    'Prepare a string with a bunch of data about the current thread.
    Dim sb As New System.Text.StringBuilder
    sb.Append(String.Format("CLR Thread ID:                       {0}{1}",
currentThread.ManagedThreadId, nl))
    sb.Append(String.Format("Windows Thread ID:                   {0}{1}",
AppDomain.GetCurrentThreadId, nl))
    sb.Append(String.Format("Thread priority:                     {0}{1}",
currentThread.Priority, nl))
    sb.Append(String.Format("Thread is in ThreadPool:             {0}{1}",
currentThread.IsThreadPoolThread, nl))
    sb.Append(String.Format("ThreadState is:                      {0}{1}",
currentThread.ThreadState.ToString, nl))
    sb.Append(String.Format("Is this a background thread:         {0}{1}",
currentThread.IsBackground, nl))
    sb.Append(String.Format("Max. worker threads in pool:         {0}{1}",
workerThreads, nl))
    sb.Append(String.Format("Max. async. I/O threads in pool:     {0}{1}",
portThreads, nl))

    MessageBox.Show(sb.ToString)
  End Sub


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Duniho  
View profile  
 More options Oct 28, 4:46 am
Newsgroups: microsoft.public.dotnet.framework
From: Peter Duniho <no.peted.s...@no.nwlink.spam.com>
Date: Tue, 27 Oct 2009 10:46:54 -0700
Local: Wed, Oct 28 2009 4:46 am
Subject: Re: How Many Threads Do I Get?

SnapDive wrote:
> I have an app that uses the stock .NET 3.5 thread pool to spawn
> background workers which do some work, make an async WCF call (which
> does some LINQ to SQL), and then quit.

> If this was an ASP.NET app I think I would be limited to 20 or 25
> threads to get things like this done before I had to use a custom
> thread pool.

AFAIK, it doesn't matter what part of .NET you're using.  ASP.NET,
coding a service, writing a Forms application, etc. they all use the
same ThreadPool defaults.  And those defaults were 25 threads per CPU in
early versions of .NET, updated to 250 threads per CPU in 2.0.  I
believe that remains the current default.

Note that the main reason for Microsoft changing the default was because
too many people were coding thread pool deadlocks, and having a much
larger pool allowed for a work-around to those bugs (with the much
larger maximum, even buggy code was much less likely to get enough
threads running for the deadlock to actually occur).

If you actually have hundreds of thread pool threads running, you may
want to reconsider the design so as to avoid that many simultaneous
operations (you should try to avoid having multiple threads all fighting
each other for CPU time).  An exception would be if your threads are all
doing some kind of i/o that involves waiting for a significant time.  In
that case, there shouldn't be much CPU contention, because the threads
are actually blocked on the i/o.

> If I am doing the above in my own Win32 service (console app), does
> the same limit apply? The hardware is a dual processor system on
> Windows Server 2003.

As I note above, I don't think the thread pool defaults vary according
to context.

Pete


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google