ThreadPool. Why why why is so difficult to set the max size? :(

B

bwahahahaha

Roll yer own. Simple array of 50 threads or whatever :D

Would be nice to have some greater control over this, in my view its a half
assed effort from them again.
 
N

Nicholas Paldino [.NET/C# MVP]

The reason that it is so hard to change the max size is because the
thread pool has been optimized to handle the number of processes in
conjunction with the processes running on the machine.

The idea is that if you have so many threads, you actually start to
shoot yourself in the foot with the time wasted in context switches.

I would recommend using the ThreadPool as is.

Hope this helps.
 
B

bwahahahaha

If you need specific gurantees, i dont recommend using the threadpool.




Nicholas Paldino said:
The reason that it is so hard to change the max size is because the
thread pool has been optimized to handle the number of processes in
conjunction with the processes running on the machine.

The idea is that if you have so many threads, you actually start to
shoot yourself in the foot with the time wasted in context switches.

I would recommend using the ThreadPool as is.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


AA said:
Why microsoft make so hard to change the max Pool Size??

I really need to change it to 50, because I'm using delegates with
BeginInvoke and I saw that they (delegates) use the ThreadPool, but I saw
too that is very complicate to change the ThreadPool size and if I want, I
need to use unmanage resources

http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=201

If I use unmanage resources my application will not be portable to
others
OS

So, somebody know another way or know something that I don't

Thanks a lot

AA
 
A

AA

Why microsoft make so hard to change the max Pool Size??

I really need to change it to 50, because I'm using delegates with
BeginInvoke and I saw that they (delegates) use the ThreadPool, but I saw
too that is very complicate to change the ThreadPool size and if I want, I
need to use unmanage resources

http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=201

If I use unmanage resources my application will not be portable to others OS

So, somebody know another way or know something that I don't

Thanks a lot

AA
 
A

AA

I think that with .net we are not only developing simple clients
applications, maybe (in my case) i'm developing a very complete server
application that requiere thousands of simultaneous transactions and my
server will be run alone in a four processor machine.

So, I think that this is a microsoft error, and for this reason a Toub (from
microsoft) designed the ManagedThreadPool. With the ManagedThreadPool we can
specify the Pool Size

The problem is that .net asynchronous operations, use the framework
ThreadPool and I can't change that. So, in my case the ManagedThreadPool is
not useful

Well, anyway thanks for your answer


AA



Nicholas Paldino said:
The reason that it is so hard to change the max size is because the
thread pool has been optimized to handle the number of processes in
conjunction with the processes running on the machine.

The idea is that if you have so many threads, you actually start to
shoot yourself in the foot with the time wasted in context switches.

I would recommend using the ThreadPool as is.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


AA said:
Why microsoft make so hard to change the max Pool Size??

I really need to change it to 50, because I'm using delegates with
BeginInvoke and I saw that they (delegates) use the ThreadPool, but I saw
too that is very complicate to change the ThreadPool size and if I want, I
need to use unmanage resources

http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=201

If I use unmanage resources my application will not be portable to
others
OS

So, somebody know another way or know something that I don't

Thanks a lot

AA
 
W

Willy Denoyette [MVP]

The number of threads in the pool is 25 times the number of CPU's per process, on a Quad CPU that gives 100 worker threads not
counting the IO threadpool (default 1000).
The value of 25 is largely sufficient most of the typical server style applications (managed or non managed), if you feel it's not
and you want a portable solution, you will need to build your own theadpool class, in the mean time you can determine the optimal
value using CorSetMaxThreads.

Willy.


AA said:
I think that with .net we are not only developing simple clients
applications, maybe (in my case) i'm developing a very complete server
application that requiere thousands of simultaneous transactions and my
server will be run alone in a four processor machine.

So, I think that this is a microsoft error, and for this reason a Toub (from
microsoft) designed the ManagedThreadPool. With the ManagedThreadPool we can
specify the Pool Size

The problem is that .net asynchronous operations, use the framework
ThreadPool and I can't change that. So, in my case the ManagedThreadPool is
not useful

Well, anyway thanks for your answer


AA



Nicholas Paldino said:
The reason that it is so hard to change the max size is because the
thread pool has been optimized to handle the number of processes in
conjunction with the processes running on the machine.

The idea is that if you have so many threads, you actually start to
shoot yourself in the foot with the time wasted in context switches.

I would recommend using the ThreadPool as is.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


AA said:
Why microsoft make so hard to change the max Pool Size??

I really need to change it to 50, because I'm using delegates with
BeginInvoke and I saw that they (delegates) use the ThreadPool, but I saw
too that is very complicate to change the ThreadPool size and if I want, I
need to use unmanage resources

http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=201

If I use unmanage resources my application will not be portable to
others
OS

So, somebody know another way or know something that I don't

Thanks a lot

AA
 
D

Dave

What kind of guarantee are you looking for? AFAIK when a work item is queued
up and there is no available thread it will create a new one. Do you have
specific timing issues that the threadpool does not satisfy?
 
A

Alvin Bruney

when you say hard what exactly do you mean? programmatically? it's a config
file setting, you change the number save the file. I missed where it was
difficult.

You really need to understand context switching and thread scheduling before
you go shoot yourself in the foot as Paldino pointed out. If you need more
than 25 threads, you either have very specialized needs or you should be
reexamining your design.
 
W

Willy Denoyette [MVP]

This is true when the number of threads is <= MaxThreads (25 per process/CPU).
If the pool is exhausted, the queud workitem will wait for a pooled thread to become free, therefore it's important to use the
threadpool only for short running, non blocking tasks.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top