|
I do; as explained, for almost every user action. There was an example-project from MS that implemented MSN Messenger in .NET, and it did the same; almost everything that took longer than 250ms was on a background thread.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
250ms is a quarter of a second, so that's "long running" in my book, in that you can't tie up the UI thread for that long.
I guess if you're doing a ton of those all the time, you may be spawning more threads to handle it, but I don't see how being able to move the window around even as the UI is lagging its update by 250ms or more all the time is much of an improvement.
Personally, I don't know enough about the app to say otherwise, but if i found i was running in to that I'd look at my design.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: I guess if you're doing a ton of those all the time, you may be spawning more threads to handle it, but I don't see how being able to move the window around even as the UI is lagging its update by 250ms or more all the time is much of an improvement. If the UI isn't updated for some time, Windows gives this nice option to close your non-responsive application. Also, usually got a thread for loading grids in the background, synchronizing a progress-bar at the same time. Gives a much better user experience than normal databinding.
MSDN states that since .NET 4, it "depends" on multiple factors. MS being helpful as always, but at least it proves Google wrong. Querying the values in a new project yields below results on my machine;
GetMinThreads - workerThreads 6, completionPortThreads 6
GetMaxThreads - workerThreads 2047, completionPortThreads 1000
GetAvailableThreads - workerThreads 2047, completionPortThreads 1000 Somehow I doubt that Max and Available are the same, but that's indeed what the framework reports.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Those are the numbers I get too. The minimums are reasonable, but the maximums are ridiculous, IMNSHO.
The only reason I can think of for microsoft to set those figures so high is to virtually guarantee that CPU bound "async" tasks are never completed synchronously. That doesn't seem right to me though. Like I said, I miss working at Microsoft, where there was someone I could shoot an email to who might know and respond.
Real programmers use butterflies
|
|
|
|
|
It may be that the "max" is equal to "available"; doesn't mean "active", but that'd be horrendously confusing.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
especially considering I am using GetAvaialableThreads() and it's the same count as GetMaxThreads()
Stephen Toub, who I trust as an expert, has been relying on his own thread pool implementation in .NET for years, and the rant in the OP i think is one of the reasons.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: The docs say it's per process, And how many? Do you have a link? Google claims this;
What is the default value for thread pool size?
5
The Max Thread Pool Size parameter specifies the maximum number of simultaneous requests the server can handle. The default value is 5. When the server has reached the limit or request threads, it defers processing new requests until the number of active requests drops below the maximum amount.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
That may be what google reports, but it's not what my actual code reports.
ETA: Are you sure that's talking about the .NET ThreadPool class?
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: ETA: Are you sure that's talking about the .NET ThreadPool class? Not quite, because I can't find the equivalent on MSDN, which I'd expect to be correct. It implies the .NET threadpool, since the other answers are about it too.
honey the codewitch wrote: That may be what google reports, but it's not what my actual code reports. I seriously dislike it when code and documentation don't come with the same answer. What I did find was another "max";
MSDN claims: There is one default thread pool per process, including Svchost.exe. By default, each thread pool has a maximum of 500 worker threads. Now, a maximum of 500 sounds reasonable, given that the average UI only uses 20 or so backgroundworkers, and perhaps 2 to 4 threads for processing data/async reading/writing.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Yeah 500 would be, just because you have all kinds of library code and framework code running along with your app code, and they need threads too.
When I design an app for throughput I do try to take that into consideration but it can only be found with profiling. Consequently, for me to know how many long running tasks i should be serving varies.
But otherwise I try to design as if I'm the only app running. The reason is if it's about moving and chunking bits fast, it's either a game, or some heavy app, or a server of some sort although those are mostly I/O bound except for things like game servers. But either way, the end user probably is aware of its requirements and will not expect it to run well with lots of other stuff going on.
The OS does a good job of scheduling its own threads so in practice I ignore OS stuff. It tends to background itself when an app is cranking anyway.
This is all just experiential. I used to write a lot of ISAPI code for work, and I had to think about what my threads were doing, and manage a "proper" thread pool. By "proper" I mean, it was directly tied to how many incoming I/O bound requests it was expected to serve - so it's a bit of a different animal but with similar concepts to say a game, or a computationally intensive app, like an mpeg encoder in that you head to very careful with how you were using the threads you had.
If I was writing something I/O bound and CPU bound, like a video player, i still wouldn't need a lot of threads. In the neighborhood of 3 depending on the system - one for I/O (so it's not tying up CPU), one for decoding (CPU bound), and one for rendering - usually tied with UI (CPU and/or GPU bound).
I guess thinking about it, I haven't run into a lot of middle ground with respect to app performance. Usually my apps either have to be casual about threading and simply reserve them for things that would lock up the UI, or they have to go full bore and do as much work as they can in the time given.
Even my parser generators were casual, despite sometimes being very long running - the LALR algorithm for example, is murder on the CPU and is resistant to being parallelized.
So maybe it's a dearth of experience on my part, wherein I would need more a "medium" app which might consistently need a lot of threads due to executing a lot of short lived but still too long for the UI tasks. I can imagine scenarios, but nothing not contrived seeming. Again, perhaps my own tunnel vision due to not finding one I've had to write.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: Yeah 500 would be As long as it doesn't start all 500 in the pool for each proces. Would explain though why the performance of my modern machine can't keep up with the UI of a Commodore Amiga. By the time the SQL Server upgrade UI appears, I clicked on the icon 10 times to "start" the damn application. Older machines give instant feedback in the UI, yet the modern ones need a few seconds to load their libraries and put up a "loading" screen.
honey the codewitch wrote: But otherwise I try to design as if I'm the only app running. Haha, very different environments and designs If you are the only app running, or have a dedicated machine, then it'd be wasteful to not use every resource there is. I usually have to assume that the user has at least one instance open of every Office-application, a mail-client, an IM client, a ton of browsers, with the user expecting a smooth experience even if they load half a gigabyte of crap into a grid.
honey the codewitch wrote: which might consistently need a lot of threads due to executing a lot of short lived but still too long for the UI tasks. I can imagine scenarios, but nothing not contrived seeming. Not just short lived; any communication using TCP, or any disk-operation, I start a backgroundworker. There's quite the amount of "professionals" that read/write in a UI-event (on mouse click or whatever), blocking the UI and making you go through all the forms' events just to get an idea of the flow.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Eddy Vluggen wrote: any communication using TCP, or any disk-operation, I start a backgroundworker.
That's an I/O bound thread, not a CPU bound thread. I'm purely talking about CPU bound worker threads here.
I/O bound threads follow different rules because they spend most of their time asleep waiting for input.
ETA: I think the context got lost in the fray, but in OP, I'm talking about CPU bound worker threads. I'm not talking about I/O bound threads. You may have many more of those than you have cores. The threadpool keeps a separate pool for those.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: That's an I/O bound thread, not a CPU bound thread. I'm purely talking about CPU bound worker threads here.
I/O bound threads follow different rules because they spend most of their time asleep waiting for input. I don't tell the BGW what kind of thread it is (except that it runs in the background, so shouldn't stop a shutdown of Windows). Not sure the ThreadPool knows that difference either.
Unless you talk about design; if you only mean generic threads meant to do processing and nothing else, then yes. Not my forte to do threads that only process (like a parser, or an Isapi-worker without UI). I just see the term "threads" and go "I create a shitload of them". Lots of apps do (some excessive, my dear Chrome), and they have little cost. Can't imagine creating over 2k threads in Delphi, just to pool them "in case".
Threading is exotic to most, and I'm talking to someone who knows his fibers (without fiberpool). For processing, my main focus is on giving the user feedback, and a time-guestimate. (Number of items existing-number of items processed) per second. So clients like me as much as they like the estimate of the copy-dialogue of Explorer.
So, this thread doesn't involve me at all, even despite it being my favorite subject?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
The .NET threadpool class at least, does indeed know the difference. It maintains two pools even - one for CPU bound threads, and one for IO bound threads. I'm not sure your background worker would know the difference, but if it was designed for just one, I'd bet it was designed primarily for I/O bound ops.
CPU bound ops just aren't as common I think?, not that they are uncommon. It's just weird that the .NET threadpool sets the available and max for CPU bound threads to 2047 per process. That's not I/O threads - which as i said, have their own pool
A thread doesn't know if it's I/O bound or CPU bound. How it works is what makes it one or the other. It would have to understand its own code to know what it was. But basically I/O bound threads sleep like cats. The wake up when there's reason
But the reason to treat them separate at least in the .NET realm is that the tasks are set up to be optimized for one style over another and giving it the hint as to what kind of work it's doing helps for performance. The other issue is a design one. Again, CPU bound work needs hardware to run on or it's just mashing the scheduler if it has to share time. That's fine, to a degree, but CPU bound threads should be considered carefully in an application.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: It maintains two pools even It's not named "TwoPools". And the BGW will prolly default to IO, since that's its most used pattern. Not that much people doing pure processing of data.
honey the codewitch wrote: A thread doesn't know if it's I/O bound or CPU bound. So how would the framework know? For most of the crap I spawn it wouldn't make much difference, but it sounds like it is important to distinguish between them.
honey the codewitch wrote: But basically I/O bound threads sleep like cats 36 hrs per 24 hrs day. Not sure if Goedzo is awake when eating.
honey the codewitch wrote: but CPU bound threads should be considered carefully in an application. The stuff drivers are made of? I don't know the difference; there's a pool and I draw upon it. If you need an article-idea, then this would confuse the hell out of people and get you some more downvotes
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Eddy Vluggen wrote: It's not named "TwoPools".
What's in a name? Try calling GetMaxThreads() or GetAvailableThreads() and they each return two values.
Eddy Vluggen wrote: So how would the framework know?
Because you tell it when you call QueueUserWorkItem() you're using a CPU bound thread - or at least one from the pool intended for that. When you use any of the items that use IO completion ports (like file or socket operations) .NET runs those on I/O threads for you.
multithreading - Simple description of worker and I/O threads in .NET - Stack Overflow[^]
Maybe that will help.
Eddy Vluggen wrote: The stuff drivers are made of?
No just the stuff you're running the processor ragged with when you call QueueUserWorkItem() . I'm not counting threads that spend most of their time sleeping.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: What's in a name? Try calling GetMaxThreads() or GetAvailableThreads() and they each return two values. From experimenting, they look the same; the max is always available. Would be sick if max equals allocated, but docs don't give a hint of that.
honey the codewitch wrote: Because you tell it when you call QueueUserWorkItem() I just create new BGW.
honey the codewitch wrote: Maybe that will help. I'll queue it, currently sleepdrunk. Third day, so not a problem yet. Not much hallucinations until day five.
"Even this, shall pass away". Thread carefully in answering.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Eddy Vluggen wrote: I just create new BGW.
I've never used BGW to be honest. I just call Task.Run() from my code, but i'm guessing it delegates to QueueUserWorkItem() , or Task.Run()/TaskFactory.StartNew()
In which case I was wrong before in guessing it was I/O thread - don't know why I thought that (i think i had isapi threadpools on the brain) but...
Eddy Vluggen wrote: I'll queue it, currently sleepdrunk.
I'm sleep deprived. Not quite into a several day stretch yet but I'm a little wobbly.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: I've never used BGW to be honest. I just call Task.Run() from my code, but i'm guessing it delegates to QueueUserWorkItem() , or Task.Run()/TaskFactory.StartNew()
In which case I was wrong before in guessing it was I/O thread - don't know why I thought that (i think i had isapi threadpools on the brain) but... BGW is a simple thread-wrapper for WinForms, and it has some simple methods for giving progress without mucking with critical sections or synchronizing variables. Saves some time if you do a task that requires both a thread and progress on the UI, defining an event for updates and stuff. Its mainly useful in UI-apps, and is a bit useless outside of that. So, shouldn't exist in a parser
honey the codewitch wrote: I'm sleep deprived. Not quite into a several day stretch yet but I'm a little wobbly. First day doesn't give me problems either; first day is enjoyable even. Day three I sound a bit drunk and slur speech, but day five I often see and hear things that aren't there. Day five is usually my worst day, and I often do anything to sleep at that point. Lots of alcohol and man sleeps, even if the sleeping pills don't work. I have no memories of reaching day six, but that doesn't mean much. The brain stops recording at day three.
Day four and five I often don't remember, or just parts of it as if it were a dream. Even going so far as becoming aggressive (I'm a pacifist and don't believe in violence). At that point, getting sleep means having a bad morning, being told what I did or said the day before.
If you sleep-deprived, go see a doctor and ask for bloody sleeping pills; you NEED them. Draw your line at day three. Anything beyond that eats your sanity and causes permanent damage. And take that warning seriously; on day three, you stop being honey and start being vinegar. Day four and five are simply damaging, both your relations and your brain. Never had a productive day beyond day three. Day four and five are mostly a haze, and cause (permanent) damage to the brain.
Today is day four again. Happens twice a month these days. A few more years, and I'll be talking to hamsters that other people can't see.
So.. if you having trouble getting sleep, see a doctor. If the doctor says "no", find another doctor. Simple as that. Find help or go a bit crazy. There's no middle ground. (And seemed more important than BGW's and threading, so hence the change in subject)
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Oh my gosh. I'm sorry you struggle with that. Until a few months ago I could not get more than 4 hours a night and sometimes i had to do with 2. That was for a few years, but now lately I've been sleeping too much. It's part of being schizoaffective so sleeping pills don't work.
Still, if i was going through what you were I'd try anything. I'm sorry to hear that.
Real programmers use butterflies
|
|
|
|
|
You are on the verge of struggling with the same; I may be your future. And your posts says you're not sleeping. If you close to schizoid, you need your sleep more than anyone.
Schizotypical eh? No clear diagnosis then. You just "weird" like me
You're in your thirties?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I'm schizoaffective, bipolar type. The diagnosis is relatively rare, and difficult, because it has symptoms of schizophrenia and bipolar disorder, but worse, presents very differently in different people.
For example, I get mixed episodes and delusional thinking but I don't hallucinate except when I'm manic - not a schizophrenic episode. I get manic though like a typical person with bipolar 1. My schizophrenia-like symptoms however, are subdued in some ways and pronounced in others. Some people with it lean more heavily on the bipolar end of things, and i lean more on the schizophrenic end of things in terms of symptoms these days, but that has changed over the course of my life.
Short answer is it's complicated. I prefer to consider myself simply "mad".
I'm not shy about it, but I have my opinions on the subject as someone living with it.
ETA: Early forties
Real programmers use butterflies
modified 19-Jul-20 22:36pm.
|
|
|
|
|
honey the codewitch wrote: Short answer is it's complicated. I prefer to consider myself simply "mad". If you not normal then mad is the default it seems. If man ever evolves, we'd label those mad too, because they not like us.
honey the codewitch wrote: 'm not shy about it, but I have my opinions on the subject as someone living with it. Glad you're open about it; I still trying to hide and not really working out.
honey the codewitch wrote: For example, I get mixed episodes and delusional thinking but I don't hallucinate except when I'm manic - not a schizophrenic episode. I get manic though like a typical person with bipolar 1. My schizophrenia-like symptoms however, are subdued in some ways and pronounced in others. Some people with it lean more heavily on the bipolar end of things, and i lean more on the schizophrenic end of things in terms of symptoms these days, but that has changed over the course of my life. I had some "incidents" which the doctor calls "episodes". Not enough symptoms for a clear diagnosis, and since no criminal record, so no priority.
Maybe too personal, but how did your environment react? Do you look forward to family meals?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I don't have a good relationship with my adoptive family. We never bonded in the first place (it's difficult for me to) and had a rocky time of it while I was growing up, including me spending a couple years as a homeless teen rather than live there.
My biological family and I get by, but then they're really understanding - mental illness runs in the family on my mom's side. Schizophrenia, and bipolar that i know of, probably a couple of schizoaffective cousins AFAIK.
My hubby on the other hand, has not only known since we were teens that something was up with me, he married me anyway sucker!
He's really understanding and helpful. I also feel better about it knowing he knew what he was getting into.
Real programmers use butterflies
|
|
|
|
|
I should add, it became easier when I stopped trying to hide it I think. There's a stigma around it but I care less about what other people think about me than what I think about me, and trying to put up a false front is exhausting. Besides, you can spot me from a mile off. I'm a very pronounced weirdo so my madness is kind of obvious to begin with. My situation may not be like yours, not saying it is. Just that I found it easier when i stopped hiding it.
I'm not sure what type of episodes you had but if you go manic it gets easier and easier to channel that into incredible creative energy if you practice.
Good luck to you.
And thanks for sharing.
Real programmers use butterflies
|
|
|
|
|