|
|
You just have to know that some humorless schmuck is going to come along and dissect this joke...
If you can't laugh at yourself - ask me and I will do it for you.
|
|
|
|
|
I recently wrote a project to demonstrate a message passing and thread pooling paradigm "in the raw" (coded manually, not using the .NET task or thread pool infrastructure) so that folks could see all the moving parts.
I wanted to make something more production ready, and to show how to do the same thing using the built in Task framework and thread pool in .NET
So I start porting the app over, and one of the things it allows you to do is get/set the number of waiting threads in the pool. Well I did that with the built in thread pool and got 2047 waiting threads back.
Even the docs suggest that's obscene:
Use caution when changing the maximum number of threads in the thread pool. While your code might benefit, the changes might have an adverse effect on code libraries you use.
Setting the thread pool size too large can cause performance problems. If too many threads are executing at the same time, the task switching overhead becomes a significant factor.
Now I know that they're all sleeping, but seriously, how many kernel wait handles does a process really need to allocate?
And it makes me wonder how reliant the Task framework really is on spawning actions on other threads. I have to believe it's performance tuned, but why so high? Do they really think we need that many waiting threads?
I expect more like a few at most for most applications, and a well written app shouldn't have more CPU bound operations than there are CPU cores (or hardware threads) when possible, so why so many?
Sometimes I miss working at microsoft. I knew which team to email with questions like this.
Thanks @JSOP for pointing me to SmartThreadPool . Even Stephen Toub wrote his own implementation of a thread pool so i think maybe I'll go that route, unless the thread i just tugged - a custom TaskScheduler can let me have my cake and eat it too.
Real programmers use butterflies
modified 18-Jul-20 11:17am.
|
|
|
|
|
Please! This is the Lounge - keep it clean!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I'm sorry I brought up Microsoft.
Real programmers use butterflies
|
|
|
|
|
Did you ask for 2047 threads (or the maximum number it supports), or is that the default number that get allocated?
|
|
|
|
|
That's what I get from calling ThreadPool.GetAvailableThreads()
GetMaxThreads() returns a much higher number (i forget it) returns the same number of threads as GetAvailableThreads() when i call it.
Oh crap. No it wasn't. I was calling GetMaxThreads()... it's 6am here, forgive me.
I was right the first time, WTH is wrong with me rn?
Real programmers use butterflies
modified 18-Jul-20 9:09am.
|
|
|
|
|
|
No doubt. I thought it was hot in here.
Real programmers use butterflies
|
|
|
|
|
This might interest you...
Multithreading, Delegates, and Custom Events[^]
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
thanks
Real programmers use butterflies
|
|
|
|
|
I already told you abou that article
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I must have missed it or forgot. Sorry. My memory isn't what it used to be. No offense.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: No offense. Don't worry... I was just bugging you a bit
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Well well. Let's see if we can get a Protector's account closed for trolling!
|
|
|
|
|
You are laughing, but... do you really consider that trolling?
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Mild trolling, sure. Which is what makes it so funny.
|
|
|
|
|
mmm... then I suppose it is a definition thing.
For me trolling is negative, done to harm or to get the other part mad on purpose.
This was more a joke, since I had no bad intentions at all, I do respect the code witch and I am not that kind of user.
Ah... and BTW it is true, I told about that JSOP's article here[^].
Just in case you think the trolling part was to lie about it
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
When you said you were just bugging Honey a bit, I thought you meant that you made the whole thing up! I'd call that mild trolling, to get a reaction, but it shouldn't bother anyone.
|
|
|
|
|
Greg Utas wrote: I thought you meant that you made the whole thing up! Nope, I didn't.
The bugging was the "I told you so", knowing that my comment went undernoticed. If not... I would have got a comment to that.
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Yes, I see that now, so it wasn't trolling in any way.
|
|
|
|
|
YOU TERRIBLE TROLL!!!!
Real programmers use butterflies
|
|
|
|
|
I just read it. It's interesting that you managed your own threadpool. The more I try to work with the built in one, the more i want to go back to my own thread pool management like i was doing before. I'll take a look at that SmartThreadPool class to see how it works. I'm interested in that.
I'm using Invoke/BeginInvoke already for my UI updates, but that's not the focus of my project, which relies on message queuing.
The thing I wonder about, is since Task.Run() uses ThreadPool , if I won't have to somehow intercept or wrap it so that it uses mine. I don't know if that's possible.
This was actually easier to do without having to consider Task or ThreadPool . Funny that.
Real programmers use butterflies
|
|
|
|
|
I think TPL manages the thread pool for you.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I figured out some more stuff. Instead of using my own thread pool, I simply changed the way Task items get scheduled, so it will queue items after it exceeds my own quota. That way it still uses the system threadpool but in a way that makes sense. the relevant class is under the Tasks namespace and it's called TaskScheduler . It's kinda neat, but not very well documented.
Real programmers use butterflies
|
|
|
|