In our previous episode, Xiangrong Fang said:
Show quoted text 6 lines
If my application needs SPEED, i.e. take full advantage of CPU
capabilities, and the application has no I/O operation at all (neither disk
nor network), it seems no need to create threads more than the number of
CPU cores ?hyper-threads)?
Am I right?
My rule of thumb is physical cores + a percentage. (like 10-20%).
The idea is to saturate the CPU, but only just so, since saturating by way too many threads increasing switching time and thus decreases performance.
The percentage is a rule of thumb approach to account for some minor I/O (if only OS background), scheduler/locks switch time, and, possibly hyperthreading.
But in my apps I always make it configurable, and use this sum only to seed the default of the configuration setting.
This because you don't always want to fully utilize the computer (e.g. to give some air to background services, or because you are working on it), and because automatic detection regularly goes wrong with new CPUs etc.