Re: Multiple Threads vs. Asynchronous IO
- From: Gianni Mariani <gi3nospam@xxxxxxxxxx>
- Date: Sat, 24 Mar 2007 01:27:49 -0700
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.
.
- Follow-Ups:
- Re: Multiple Threads vs. Asynchronous IO
- From: Frank Cusack
- Re: Multiple Threads vs. Asynchronous IO
- References:
- Multiple Threads vs. Asynchronous IO
- From: chsalvia
- Re: Multiple Threads vs. Asynchronous IO
- From: Gianni Mariani
- Re: Multiple Threads vs. Asynchronous IO
- From: David Schwartz
- Multiple Threads vs. Asynchronous IO
- Prev by Date: Re: Multiple Threads vs. Asynchronous IO
- Next by Date: Re: Mult-thread macro
- Previous by thread: Re: Multiple Threads vs. Asynchronous IO
- Next by thread: Re: Multiple Threads vs. Asynchronous IO
- Index(es):
Relevant Pages
|