Joshua Bloch: Performance Anxiety – on Performance Unpredictability, Its Measurement and Benchmarking
Join the DZone community and get the full member experience.Join For Free
- nowadays, performance is completely non-predictable. you have to measure it and employ proper statistics to get some meaningful results.
- microbenchmarking is very, very hard to do correctly. no, you misunderstand me, i mean even harder than that!
- from the resources: profiles and result evaluation methods may be very misleading unless used correctly.
there has been another blog about it but i’d like to record here more detailed remarks.
today we can’t estimate performance, we must measure it because the systems (jvm, os, processor, …) are very complex with many different heuristics on various levels and thus the performance is highly unpredictable . this doesn’t apply only to java, but also to c, c++, even to assembly code.
example : results during a single jvm run may be consistent (warm-up, then faster) but can vary between jvm executions even by 20%. one of the causes may be compilation planning (what’s inlined, …) – it’s done in a background thread and thus is inherently non-deterministic.
therefore don’t estimate but measure and not only that – also do statistical processing of the data (how often diff. values appear, what they are, … – mean, median, standard deviation etc.).
“ profiles don’t help much ; in fact, they can mislead” – mytkowicz, diwan etc. – “evaluating the accuracy of java proﬁlers” , pldi ’10 – in their experiment, each of 4 leading profiles identified a different hotspot. i’d really recommend you reading the related stackoverflow discussion “if profiler is not the answer, what other choices do we have?” (the answer is: profilers have their value, but use the correct ones and use them correctly). the conclusion of the original paper:
our results are disturbing because they indicate that proﬁler incorrectness is pervasive—occurring in most of our seven benchmarks and in two production jvm—-and signiﬁcant—all four of the state-of-the-art proﬁlers produce incorrect proﬁles. incorrect proﬁles can easily cause a performance analyst to spend time optimizing cold methods that will have minimal effect on performance. we show that a proof-of-concept proﬁler that does not use yield points for sampling does not suffer from the above problems.
“benchmarking is really, really hard!” and “ most benchmarks are seriously broken “. broken means that either the measurement’s error is higher than the value being measured or that the results obtained are unrelated to intended measurements. it seems that it is actually really hard to find a (micro)-benchmark, which isn’t broken. joshua recommends cliff click’s javaone 2009 presentation the art of (java) benchmarking (see also an interesting related interview with cliff), which i belive to have seen and which points out the various traps here. joshu also mentiones that some frameworks, such as google caliper may help you to avoid the pitfalls, though i’m quite sure they can’t protect you from all.
joshua mentiones a couple of interesting papers , you should check the slides for them. one which sounds really interesting to me is by georges, buytaert and eeckhout – statistically rigorous java performance evaluation , oopsla07 (20 pages). they mention there that you need to run vm 30 times to get meaningful data. from the abstract :
this paper shows that prevalent methodologies can be misleading, and can even lead to incorrect conclusions. the reason is that the data analysis is not statistically rigorous. in this paper, we present a survey of existing java performance evaluation methodologies and discuss the importance of statistically rigorous data analysis for dealing with non-determinism. we advocate approaches to quantify startup as well as steady-state performance, and, in addition, we provide the javastats software to automatically obtain performance numbers in a rigorous manner. although this paper focuses on java performance evaluation, many of the issues addressed in this paper also apply to other programming languages and systems that build on a managed runtime system.
i find this subject very interesting because for over a year i’m involved in performance optimization of one of our data feeds, which used to run for couple of days (latest results: 1/2h [with a bit of cheating]). my experience completely supports what joshua says – don’t guess but measure, profilers may be misleading, performance is unpredictable. though as a collegue mentioned, in the domain of enterprise java, our performance problems are usually caused by the database and communication with it (which 100% applies to that feed too).
i’ve already blogged about some experiences, e.g. in the power of batching or speeding jdbc by 100 (inspired by jdbc performance tuning with fetch size ), check also the performance tag for interesting links. i also appreciated and applied the knowledge from accurately computing running variance (i often wish i have slept less and paid attention more during the uni math lectures ).
the higher complexity, the higher unpredictability =>
- as an application programmer, use high-level, declarative constructs where posible to push the responsability for performance one level down to library and jvm authors, who should know better.
- measure repeatedly and process the results with proper statistics. don’t forget to repeat them over time, the platform evolves with every release.
once again, microbenchmarking is hard! if you have to play with it, use something like caliper and be aware that your results are most likely wrong anyway.
Opinions expressed by DZone contributors are their own.