Java Reference
In-Depth Information
with many optimizations are bad enough—you don't want to pay these costs if you don't need
to—and you definitely don't want to pay them if you don't even get the desired benefit.
Measure, don't guess.
There are sophisticated profiling tools on the market for measuring performance and tracking
down performance bottlenecks, but you don't have to spend a lot of money to figure out what
your program is doing. For example, the free perfbar application can give you a good pic-
ture of how busy the CPUs are, and since your goal is usually to keep the CPUs busy, this
is a very good way to evaluate whether you need performance tuning or how effective your
tuning has been.
11.2. Amdahl's Law
Some problems can be solved faster with more resources—the more workers available for
harvesting crops, the faster the harvest can be completed. Other tasks are fundamentally seri-
al—no number of additional workers will make the crops grow any faster. If one of our
primary reasons for using threads is to harness the power of multiple processors, we must
also ensure that the problem is amenable to parallel decomposition and that our program ef-
fectively exploits this potential for parallelization.
Most concurrent programs have a lot in common with farming, consisting of a mix of paral-
lelizable and serial portions. Amdahl's law describes how much a program can theoretically
be sped up by additional computing resources, based on the proportion of parallelizable and
serial components. If F is the fraction of the calculation that must be executed serially, then
Amdahl's law says that on a machine with N processors, we can achieve a speedup of at most:
As N approaches infinity, the maximum speedup converges to 1/ F , meaning that a program
in which fifty percent of the processing must be executed serially can be sped up only by
a factor of two, regardless of how many processors are available, and a program in which
ten percent must be executed serially can be sped up by at most a factor of ten. Amdahl's
law also quantifies the efficiency cost of serialization. With ten processors, a program with
Search WWH ::




Custom Search