473,513 Members | 3,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threads vs Thread Pool

Does the magic number of 25 only apply to the thread pool? Does it also
apply to manually creating threads?

May 6 '06 #1
11 2802
It applies only to thread pool and not to threads. The threadpool size
also can be changed from 25 to a greater number.

May 6 '06 #2
"Naveen" <na*********************@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
It applies only to thread pool and not to threads. The threadpool size
also can be changed from 25 to a greater number.


The default cap in the thread pool is 25 thread *per processor* so on a 2
processor machine it defaults to 50. However, in v2.0 you can change the
number of threads the thread pool caps to via the ThreadPool.SetMaxThreads()
call.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
May 6 '06 #3
25 is just a default and you can configure it. As for your own threads, you
can keep creating as many as you want ... until you crash the machine, that
is. :-)

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
"vzaffiro" <Vi*************@gmail.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
Does the magic number of 25 only apply to the thread pool? Does it also
apply to manually creating threads?

May 6 '06 #4
<splittinghairs>
you will run out of stack space long before you crash the machine on most
machines

A process in windows is generally only allowed 2 gb of memory ... by default
every thread that you start up uses 1 mb of stack space. As such the maximum
would be 2000 :) You can however set the stack size of threads (in 1.x via a
direct call to CreateThread, in 2.0 an overloaded constructor)
</splittinghairs>

:)

Cheers,

Greg
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in
message news:eo**************@TK2MSFTNGP02.phx.gbl...
25 is just a default and you can configure it. As for your own threads,
you can keep creating as many as you want ... until you crash the machine,
that is. :-)

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
"vzaffiro" <Vi*************@gmail.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
Does the magic number of 25 only apply to the thread pool? Does it also
apply to manually creating threads?


May 6 '06 #5
> you will run out of stack space long before you crash the machine on most
machines Nope. As I demonstrated earlier this week, the machine crashes long before
the out of memory exception is thrown.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"Greg Young" <Dr*************@hotmail.com> wrote in message
news:uO**************@TK2MSFTNGP03.phx.gbl... <splittinghairs>
you will run out of stack space long before you crash the machine on most
machines

A process in windows is generally only allowed 2 gb of memory ... by
default every thread that you start up uses 1 mb of stack space. As such
the maximum would be 2000 :) You can however set the stack size of threads
(in 1.x via a direct call to CreateThread, in 2.0 an overloaded
constructor)
</splittinghairs>

:)

Cheers,

Greg
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in
message news:eo**************@TK2MSFTNGP02.phx.gbl...
25 is just a default and you can configure it. As for your own threads,
you can keep creating as many as you want ... until you crash the
machine, that is. :-)

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
"vzaffiro" <Vi*************@gmail.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
Does the magic number of 25 only apply to the thread pool? Does it also
apply to manually creating threads?



May 6 '06 #6
Hello Cowboy (Gregory A. Beamer),

Take into accout that they say the 25 is the maximum number if thead that
can give u visible performance.
Increasing that number of thread don't give u any advantage, notwithstanding
the system size and complexity.
C> 25 is just a default and you can configure it. As for your own
C> threads, you can keep creating as many as you want ... until you
C> crash the machine, that is. :-)

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
May 7 '06 #7
"Michael Nemtsev" <ne*****@msn.com> wrote in message
news:9c**************************@msnews.microsoft .com...
Hello Cowboy (Gregory A. Beamer),

Take into accout that they say the 25 is the maximum number if thead that
can give u visible performance.
Increasing that number of thread don't give u any advantage,
notwithstanding the system size and complexity.


I think thats possibly a bit of a generalisation. For example, ASP.NET
increases this value to 50 by default. Surely it depends on what the
appliction is doing, how much contention there is for shared resources and
that kind of thing.

For example, if I had a remoting server (remoting dispatches calls on thread
pool threads) and those remoting calls were accessing discrete parts of a
database or separate files on the file system why would limiting the app to
25 concurrent calls be a good thing and what would prevent those calls from
being multiplexed higher by increasing the maxiumum umber of threads in the
pool?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
May 7 '06 #8
Hello Richard Blewett [DevelopMentor]" richard at nospam dotnetconsult dot
co dot uk,

Yep, it's only generalization. AFAIK they choose number 25 as a golden mean.

But as you say, everything depends on our own project. We need to measure
the cost of thread's context switch and decide whether is there any advantage
of increasing the number of our thread.
Take into accout that they say the 25 is the maximum number if thead
that
can give u visible performance.
Increasing that number of thread don't give u any advantage,
notwithstanding the system size and complexity.

R> I think thats possibly a bit of a generalisation. For example,
R> ASP.NET increases this value to 50 by default. Surely it depends on
R> what the appliction is doing, how much contention there is for shared
R> resources and that kind of thing.
R>
R> For example, if I had a remoting server (remoting dispatches calls on
R> thread pool threads) and those remoting calls were accessing discrete
R> parts of a database or separate files on the file system why would
R> limiting the app to 25 concurrent calls be a good thing and what
R> would prevent those calls from being multiplexed higher by increasing
R> the maxiumum umber of threads in the pool?

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
May 7 '06 #9

"Richard Blewett [DevelopMentor]" <richard at nospam dotnetconsult dot co
dot uk> wrote in message news:uU**************@TK2MSFTNGP02.phx.gbl...
| "Michael Nemtsev" <ne*****@msn.com> wrote in message
| news:9c**************************@msnews.microsoft .com...
| > Hello Cowboy (Gregory A. Beamer),
| >
| > Take into accout that they say the 25 is the maximum number if thead
that
| > can give u visible performance.
| > Increasing that number of thread don't give u any advantage,
| > notwithstanding the system size and complexity.
|
| I think thats possibly a bit of a generalisation. For example, ASP.NET
| increases this value to 50 by default. Surely it depends on what the
| appliction is doing, how much contention there is for shared resources and
| that kind of thing.
|
| For example, if I had a remoting server (remoting dispatches calls on
thread
| pool threads) and those remoting calls were accessing discrete parts of a
| database or separate files on the file system why would limiting the app
to
| 25 concurrent calls be a good thing and what would prevent those calls
from
| being multiplexed higher by increasing the maxiumum umber of threads in
the
| pool?
|
| Regards
|
| Richard Blewett - DevelopMentor
| http://www.dotnetconsult.co.uk/weblog
| http://www.dotnetconsult.co.uk
|
|

Richard,
In the remoting scenario (and ASP.NET) , the requests are handled by the
Completion port threads not on the worker threads from the thread pool.
You can check this by calling ThreadPool.GetAvailableThreads.
In a remote server application of mine where I have 50 clients
simultaneously calling a remoting server, I get the following values for the
thread pool threads:

Max worker threads = 50, available = 50
Max I/O threads = 1000, available = 995

Note that this was taken on a dual CPU box (hence the 50 workers), see there
are no worker threads taken, the number of IOCP threads varies between 2 and
6, but this highly depends on the task, but I never saw more than 10-12 IOCP
threads running on a dual CPU box.

Willy.
May 7 '06 #10
> Richard,
In the remoting scenario (and ASP.NET) , the requests are handled by the
Completion port threads not on the worker threads from the thread pool.
You can check this by calling ThreadPool.GetAvailableThreads.
In a remote server application of mine where I have 50 clients
simultaneously calling a remoting server, I get the following values for
the
thread pool threads:

Max worker threads = 50, available = 50
Max I/O threads = 1000, available = 995

Note that this was taken on a dual CPU box (hence the 50 workers), see
there
are no worker threads taken, the number of IOCP threads varies between 2
and
6, but this highly depends on the task, but I never saw more than 10-12
IOCP
threads running on a dual CPU box.

Willy.


Ahh interesting - I knew it was handled by the threadpool but I always
assumed it was worker threads (although i guess its up to the channel) - thx
for the clarification.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
May 7 '06 #11

"Richard Blewett [DevelopMentor]" <richard at nospam dotnetconsult dot co
dot uk> wrote in message news:el**************@TK2MSFTNGP03.phx.gbl...
|> Richard,
| > In the remoting scenario (and ASP.NET) , the requests are handled by the
| > Completion port threads not on the worker threads from the thread pool.
| > You can check this by calling ThreadPool.GetAvailableThreads.
| > In a remote server application of mine where I have 50 clients
| > simultaneously calling a remoting server, I get the following values for
| > the
| > thread pool threads:
| >
| > Max worker threads = 50, available = 50
| > Max I/O threads = 1000, available = 995
| >
| > Note that this was taken on a dual CPU box (hence the 50 workers), see
| > there
| > are no worker threads taken, the number of IOCP threads varies between 2
| > and
| > 6, but this highly depends on the task, but I never saw more than 10-12
| > IOCP
| > threads running on a dual CPU box.
| >
| > Willy.
| >
| >
|
| Ahh interesting - I knew it was handled by the threadpool but I always
| assumed it was worker threads (although i guess its up to the channel) -
thx
| for the clarification.
|

Well, I'm using tcp (across the network) and ipc (cross-process)channels and
both are using IOCP threads to handle the requests, this is quite normal as
both use the asynchronous I-O support mapped on CP's in .NET.
Note that in a tcp scenario, the number of CP threads used highly depend on
the number of CPU's and their speed, the network speed and topology and the
actual network load and the call payload.
Willy.
May 7 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4545
by: AnalogKid | last post by:
Short question: What's the difference between SingleUse and MultiUse ? Long question: I've been writing some sample code to see how different Instancing values and threading models work. I tried all main combinations of Instancing (Multiuse/Singleuse) and of Threading models (per object/pool). Here's what I found: MultiUse - Thread per...
6
2735
by: Max Adams | last post by:
Threads and ThreadPool's If I use a ThreadPool how can I tell when a thead in the threadpool has exited? I don't want to set a global member variable I would much rather be able to act on an event Also (failing this ThreadPool issue) is it possible to create an array of Worker Threads, can anyone illustrate with code please Thanks
9
1864
by: Eric Sabine | last post by:
Can someone give me a practical example of why I would join threads? I am assuming that you would typically join a background thread with the UI thread and not a background to a background, but since I'm asking in the first place, assume that assumption to be very assuming. thanks, Eric
6
4419
by: Quiet Man | last post by:
Hi all, I'm designing a fairly simple service that will run on W2K/SP4 and W2K3 servers. It's job is to be a very specialized database server that listens on a given IP address / TCP port and handles multiple connections. Client programs will make a connection and pass text strings to the service, which will then return a value for each of...
11
20319
by: Peter Kirk | last post by:
Hi there I am looking at using a thread-pool, for example one written by Jon Skeet (http://www.yoda.arachsys.com/csharp/miscutil/). Can anyone tell me if this pool provides the possibility to wait for all its threads to finish? For example, if I start 20 threads: CustomThreadPool pool = new CustomThreadPool("PetersThreadPool");...
4
1712
by: Manuel | last post by:
I have a long function that needs to be done 1000 times. I'm multithreading it, but I don't want to load them up all at once, instead load them 10 at a time. So far the only way I can get it to work is by creating a dummy form with a timer. On the timer function I test if the number of threads are less than 10 then run the remaining ones....
0
1157
by: TY | last post by:
Hi Everyone, I have a multithreading application, a typical Main thread that uses the ThreadPool.QueueUserWorkItem method to add new threads to the Thread POOL. I need a way to control the threads created by the thread pool because some created threads go indefinilty for a long period of time and I would like to terminate these threads. I...
15
2596
by: Bryce K. Nielsen | last post by:
I have an object that starts a thread to do a "process". One of the steps inside this thread launches 12 other threads via a Delegate.BeginInvoke to process. After these 12 threads are launched, the main thread waits. At the completion of each subthread, the mainthread checks all 12 thread objects to see if they are done. If they are, raise an...
4
3994
by: gsimmons | last post by:
I've been researching multi-threaded WinForms apps and thread synchronization stuff for a couple days since I'm working on refactoring a multi-threaded GUI app at work and want to be sure it's rock solid/thread-safe. I've seen all the posts about using BeginInvoke to have worker threads interact with the UI. My question is this: I created a...
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7125
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5703
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3252
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3239
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.