Re: Multiple Threads vs. Asynchronous IO



David Schwartz wrote:
On Mar 22, 1:07 pm, Gianni Mariani <gi3nos...@xxxxxxxxxx> wrote:


To get the most out of your system, the number of threads should equal
the number of cores available. This means you can keep all the cores
busy. An event driven multi-threaded model where you have a limited
number of "worker" threads usually is the best model.


Keeping cores busy is just one of the things threads do. So you should
have *at* *least* as many threads as cores. You should have as many
threads as things that must block that you want to do at the same
time.

For example, suppose you need to read a lot of files from many
different disks. If I have two cores and five disks, two threads will
not get me maximum read performance.

Similarly, if I have two cores and two threads, what happens if a code
page faults? One thread will be stalled until the code can be read
from a potentially very busy disk. Until that happens, I'm wasting a
core.


Yes, sure, some system calls as well as page faults block and there is little you can do. However, if you have a fully event driven system then nothing *should* block and even page faults should have a minimal impact. In a true event driven system, every thread would be compute bound, except for when a thread waits for a new event which by definition there is nothing to do anyway.

I usually find that adding one more thread than CPU gives peak or close to peak performance if the system is truly (mostly) event driven and it's only a small percentage difference.

.



Relevant Pages

  • Re: [opensuse] systemload / cpus
    ... I noticed on one of my machines, one of the cores was permanently 100% ... These programs, as are most programs, are single process/thread. ... If you have a tool that shows which CPU is busy, ...
    (SuSE)
  • Re: Photoshop CS3 multithreading
    ... all 4 cores are veru busy. ... Similar things happen with various filters, ... or all 4 cores are very busy. ...
    (comp.graphics.apps.photoshop)
  • Re: Multiple Threads vs. Asynchronous IO
    ... This means you can keep all the cores ... An event driven multi-threaded model where you have a limited ... Keeping cores busy is just one of the things threads do. ... If I have two cores and five disks, ...
    (comp.programming.threads)
  • [opensuse] systemload / cpus
    ... I noticed on one of my machines, one of the cores was permanently 100% ... busy, while others were stile idle. ... (two dual-cores) ...
    (SuSE)