Grokking concurrency, message passing and Co

div0 div0 at users.sourceforge.net
Mon Jul 12 09:41:12 PDT 2010


On 12/07/2010 02:50, sybrandy wrote:
>>>>>> The rule of thumb is don't bother spawning more threads than you
>>>>>> have cpus. You're just wasting resources mostly.
>>>>>>
>>>>> You REALLY don't want more threads trying to run than you have cores.
>>>>> Threads in a wait state, are less of an issue, but they still use up
>>>>> resources.
>
>>
>> Personally I'd never use more threads than cores as a program design,
>> but I'm a performance whore. ;)
>>
>
> Could you explain why you believe this a bit more? I'm curious because
> I've worked with databases and the rule of thumb there was you should
> configure them to use twice as many threads as number of cores/CPUs. The
> reasoning, I believe, is that if one thread on the CPU is stalled,
> another thread can execute in it's place. And yes, I believe this was
> before hyperthreading.
>
> Though I wasn't informed of the specifics as to why, I'm guessing it's
> mainly because with a database, there's a good chance you have to
> perform some sort of disk I/O. Therefore instead of having the CPU wait
> while the I/O is occurring, another thread can start executing while the
> original is waiting.
>
> Casey

I'd expect databases to have quite odd performance characteristics 
compared to a more normal application though; You'd expect them to be IO 
bound most of the time, so having more threads than cores sounds like a 
reasonable thing to do.

If you aren't waiting on the disc, then more threads aren't going to 
help, they'll just be contending for cpu time as BCS said.

Still that's one of the drawbacks with multi threading, there's really 
not many absolute statements you can make or things you can assume.

You'll have to profile you application and fiddle with it to find out 
how to get the best performance out of it.

-- 
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk


More information about the Digitalmars-d-learn mailing list