Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is actually a hard set of questions to which there are no absolute answers, but the following should serve as decent approximations:</p> <ol> <li><p>It is a function of your application behavior and your runtime environment, and can only be deduced by experimentation. There is usually a threshold after which your performance actually degrades as you increase the number of threads.</p></li> <li><p>Usually, after you find your limits, you have to figure out how to redesign your application such that the cost-per-thread is not as high. (Note that for some domains, you can get better performance by redesigning your algorithm and reducing the number of threads.) </p></li> <li><p>There is no general "ideal" number of threads, but you can <em>sometimes</em> find the optimal number of threads for an application on a specific runtime environment. This is usually done by experimentation, and graphing the results of benchmarks while varying the following:</p> <ul> <li>Number of threads.</li> <li>Buffer sizes (if the data is not in RAM) incrementing at some reasonable value (e.g., block size, packet size, cache size, etc.)</li> <li>Varying chunk sizes (if you can process the data incrementally).</li> <li>Various tuning knobs for the OS or language runtime.</li> <li>Pinning threads to CPUs to improve locality.</li> </ul></li> <li><p>There are many factors that affect thread limits, but the most common ones are:</p> <ul> <li>Per-thread memory usage (the more memory each thread uses, the fewer threads you can spawn)</li> <li>Context-switching cost (the more threads you use, the more CPU-time is spent switching).</li> <li>Lock contention (if you rely on a lot of coarse grained locking, the increasing the number of threads simply increases the contention.)</li> <li>The threading model of the OS (How does it manage the threads? What are the per-thread costs?)</li> <li>The threading model of the language runtime. (Coroutines, green-threads, OS threads, sparks, etc.)</li> <li>The hardware. (How many CPUs/cores? Is it hyperthreaded? Does the OS loadbalance the threads appropriately, etc.)</li> <li>Etc. (there are many more, but the above are the most important ones.)</li> </ul></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload