473,417 Members | 1,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

Question about ThreadPool

Hi,

I see in the ThreadPool documentation that the pool has a default limit of
25 threads.

Is it correctly understood that this limit is for my entire application? So
if I have several worker-threads each using "ThreadPool.QueueUserWorkItem"
then the limit is spread over all my worker-threads - so if
"worker-thread-1" currently has 20 calls in progress then there are only 5
thread-pool threads available for "worker-thread-2" ?

Thanks,
Peter
Nov 17 '05 #1
5 1670
So you have 2 worker threads each making calls to ThreadPool.QueueUserWorkItem.

The thread pool limit is 25 threads *per processor* and is a per process limit. This value cannot be changed from managed code (this changes in v2.0) although there is an unmanaged code API to do it. Mike Woodring has written a sample that wraps the necessary interop calls in a .NET component [1].

The one question really is what are these thread pool threads doing? The threadpool is really for relatively short lived work - if you are exhausting the thread pool you must be generating alot of threadpool work or the each work item must be taking a while to execute.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

[1] http://www.bearcanyon.com/dotnet/#tpcontrol

Hi,

I see in the ThreadPool documentation that the pool has a default limit of
25 threads.

Is it correctly understood that this limit is for my entire application? So
if I have several worker-threads each using "ThreadPool.QueueUserWorkItem"
then the limit is spread over all my worker-threads - so if
"worker-thread-1" currently has 20 calls in progress then there are only 5
thread-pool threads available for "worker-thread-2" ?

Thanks,
Peter

Nov 17 '05 #2
I think it's 25 threads per AppDomain? Anyhow, ThreadPool should only
be used when performing operations that will not run a very long time.
It ti will run a long time you should create your own thread like this:
Thread WorkerThread = new Thread(new ThreadStart(MyWorkerThreadFun));
WorkerThread.Name = "My Worker Thread"; // looks nice in Output
window
WorkerThread.Start();

and the function should look like this

private void MyWorkerThreadFun()
{
}

Nov 17 '05 #3
"Richard Blewett [DevelopMentor]" <ri******@NOSPAMdevelop.com> skrev i en
meddelelse news:uD****************@tk2msftngp13.phx.gbl...
So you have 2 worker threads each making calls to
ThreadPool.QueueUserWorkItem.

The thread pool limit is 25 threads *per processor* and is a per process
limit. This value cannot be changed from managed code (this changes in
v2.0) although there is an unmanaged code API to do it. Mike Woodring has
written a sample that wraps the necessary interop calls in a .NET
component [1].

The one question really is what are these thread pool threads doing? The
threadpool is really for relatively short lived work - if you are
exhausting the thread pool you must be generating alot of threadpool work
or the each work item must be taking a while to execute.


I have a lot of work to do. I have to execute about 10000 queries against a
search engine, each of which will take a long time (15 seconds to 5 minutes)
to complete.

I wanted to put these into some threads to try to help throughput. Obviously
10000 threads is too much - but what is good? I though 25 threads sounded
too little. I must admit that I haven't actually tested anything yet because
there is no real data yet to work on - I know one shouldn't "optimise" too
early, and maybe the search engine won't handle a large number of
simultaneous requests anyway... so maybe I need to wait, just wanted to keep
ahead.

Any advice appreciated.
Thanks,

Peter
Nov 17 '05 #4
Peter Kirk wrote:
"Richard Blewett [DevelopMentor]" <ri******@NOSPAMdevelop.com> skrev
i en meddelelse news:uD****************@tk2msftngp13.phx.gbl...
The one question really is what are these thread pool threads doing?
The threadpool is really for relatively short lived work - if you are
exhausting the thread pool you must be generating alot of threadpool
work or the each work item must be taking a while to execute.


I have a lot of work to do. I have to execute about 10000 queries
against a search engine, each of which will take a long time (15
seconds to 5 minutes) to complete.

I wanted to put these into some threads to try to help throughput.
Obviously 10000 threads is too much - but what is good? I though 25
threads sounded too little. I must admit that I haven't actually
tested anything yet because there is no real data yet to work on - I
know one shouldn't "optimise" too early, and maybe the search engine
won't handle a large number of simultaneous requests anyway... so
maybe I need to wait, just wanted to keep ahead.


The built in Thread Pool is not the solution to your problem. It's designed
for short, high CPU, low I/O operations. Your requirements are long, low
CPU, high I/O operations.

I see 2 alternatives:

1. Build your own thread pool which will balance things to your needs.
This can be quite challenging.

2. Use Asynchronous I/O. This is likely the optimal way to go. You could
use the build in Thread Pool to handle the return information from the Async
I/O... that'd probably work fairly well.

By the way, it's entirely possible to overwhelm the target system with a
huge number of outstanding requests. You'll want to be careful about that,
I would expect.

--
Reginald Blue
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone."
- Bjarne Stroustrup (originator of C++) [quoted at the 2003
International Conference on Intelligent User Interfaces]
Nov 17 '05 #5
Peter Kirk <pk@alpha-solutions.dk> wrote:
I wanted to put these into some threads to try to help throughput. Obviously
10000 threads is too much - but what is good? I though 25 threads sounded
too little. I must admit that I haven't actually tested anything yet because
there is no real data yet to work on - I know one shouldn't "optimise" too
early, and maybe the search engine won't handle a large number of
simultaneous requests anyway... so maybe I need to wait, just wanted to keep
ahead.


If they're all going to the same database, the chances are that having
more than a few threads won't actually increase the throughput at all.
You only gain performance if you're spreading your bottleneck out over
different resources.

However, I'd suggest not using the system threadpool, but a custom one.
That way you end up with a far smaller chance of deadlocking, because
you know the system won't be trying to use the same threadpool for
async calls etc.

See http://www.pobox.com/~skeet/csharp/miscutil

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6

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

Similar topics

5
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
5
by: Richard P | last post by:
I need some help on timers. My app is asp.net 1.1 website running in a shared hosting environment with a third-party service provider. I currently request and cache 20 - 40 remote RSS feeds. When a...
5
by: Duane Pressley | last post by:
I'm looking for someone to help me make sense of the results I'm observing when using the ThreadPool class in a COM-Interop scenario. Here's the set up: 1.. A classic ASP page instantiates and calls...
4
by: Gary Short | last post by:
Hello group, I'm writing a spidering app and I'd appreciate some advice on threading. My plan of attack is to have a main thread fetching the html from a list of urls in a xml file, then...
1
by: John | last post by:
Hi I have some difficulties understanding some issues with multithreading: *What is the meaning of: "implement a method to run each update call in its own thread" *If i have a component that...
5
by: admin | last post by:
ok This is my main. Pretty much it goes through each category and starts up 4 worker threads that then ask for groups to gether from. My problem is that when the thread gets done it keeps the...
19
by: frankiespark | last post by:
Hello all, I was perusing the internet for information on threading when I came across this group. Since there seems to be a lot of good ideas and useful info I thought I'd pose a question. ...
3
by: =?Utf-8?B?TWljaGFlbE4=?= | last post by:
I am designing a multi-threaded application which responds to a FileSystemWatcher events. Depending on the file created, I need to either archive the file to a specific directory, or process the...
1
by: Shree | last post by:
On Aug 22, 1:01 pm, "Brian Stoop" <b.st...@consultant-spam.free.com> wrote: A simple way could be to keep a static counter which can be updated in the call back function "TestThread1". Make the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.