Java Performance Tuning
Java(TM) - see bottom of page
Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks!
Training online: Concurrency, Threading, GC, Advanced Java and more ...
Tips January 2011
JProfiler
|
Get rid of your performance problems and memory leaks!
|
JProfiler
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 122 contents
http://jnb.ociweb.com/jnb/jnbDec2010.html
Six JDK Classes You Think You Know (Page last updated December 2010, Added 2011-01-30, Author Weiqi Gao, Publisher OCIWeb). Tips:
- Thread.setDefaultUncaughtExceptionHandler and Runtime.addShutdownHook can interact unexpectedly and cause a deadlock because if Runtime.exit() is invoked after the virtual machine has begun its shutdown sequence then if shutdown hooks are being run it will block indefinitely.
http://theholyjava.wordpress.com/2010/12/10/joshua-bloch-performance-anxiety-on-unpredictability/
Joshua Bloch: Performance Anxiety - on Performance Unpredictability, Its Measurement and Benchmarking (Page last updated December 2010, Added 2011-01-30, Author Jakub Hol?, Publisher theholyjava). Tips:
- 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.
- Results during a single JVM run may be consistent (warm-up, then faster) but can vary between JVM executions even by 20%.
- Do statistical processing of the data (how often diff. values appear, what they are, mean, median, standard deviation etc.).
- For performance testing you need to run VM 30 times to get meaningful data.
- As an application programmer, use high-level, declarative constructs where posible to push the responsibility for performance one level down to library and JVM authors, who should know better.
http://parleys.com/#sl=3&st=5&id=2103
Performance Anxiety (Page last updated December 2010, Added 2011-01-30, Author Joshua Bloch, Publisher Devoxx). Tips:
- Low level optimization is only relevant for compilers and library writers.
- It is impossible to estimate modern performance from reading code because of the level of abstraction. Even chips do speculative execution - && used to be faster than &, but nowadays it normally isn't because of branch prediction!
- You have to measure (and employ proper statistics - mean, stddev, etc) to get meaningful results.
- You can see 20% variations between runs of simple code.
- Compilation planning is non-deterministic - which makes everything else non-deterministic.
- Complexity and predictability are inversely related. After you have done the obvious optimizations, better performance usually produces more complexity.
- Run tests 30 times to get meaningful data
- Profilers can mislead and are not consistent
- Use high level constructs (e.g. the library sort rather than your own sort)
- Don't benchmark - you'll get it wrong (almost always either the errors are larger than the measure, or you are measuring something other than you meant to measure).
http://www.developer.com/java/web/article.php/3909666
Jetty Continuations: Push Your Java Server Beyond Its Scalability Limits (Page last updated October 2010, Added 2011-01-30, Author Manish Malhotra, Publisher developer.com). Tips:
- Continuations suspend a request and releases the thread to the thread pool. When an event or timeout occurs, it resumes the suspended request. This approach avoids a thread-per-request limitation where requests would otherwise suspend threads for a non-CPU operations.
- A continuation implementation can suspend, resume, and timeout requests, and callback on timeouts and on completion.
http://kirk.blog-city.com/benchmarks_gone_wild_part_1_watch_the_clock.htm
Benchmarks Gone Wild: Part 1 (Page last updated October 2010, Added 2011-01-30, Author Kirk Pepperdine, Publisher kodewerks). Tips:
- System.currentTimeMillis typically has a resolution that is too low to measure short execution times (anything that will take less than a few milliseconds).
- -XX:+PrintCompilation will tell you when things are being JIT compiled, so is useful for knowing when the steady state has been reached after which timings should be consistent (and optimal).
http://www.javaspecialists.eu/archive/Issue188.html
Interlocker - Interleaving Threads (Page last updated October 2010, Added 2011-01-30, Author Dr. Heinz M. Kabutz, Publisher The Java Specialists' Newsletter). Tips:
- You can release a semaphore from a thread that has not acquired it. This is quite different to locks, where only the thread that acquired the lock can release it.
- Three blocking ways to transfer execution determinstically between threads are: wait-notify; java.util.concurrent.locks
.Condition; Alternating java.util.concurrent.Semaphore;
- A lock free mechanism to transfer execution determinstically between threads would use a spin lock on a volatile variable. The threads waiting to proceed continually check the volatile spin lock to see if it is their turn to proceed, then set the spin lock to the next thread after they have completed. This is very CPU expensive as all threads checking the spin lock are using a full core each, but is very fast to transfer control to the next thread.
Jack Shirazi
Back to newsletter 122 contents
Last Updated: 2024-12-27
Copyright © 2000-2024 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
URL: http://www.JavaPerformanceTuning.com/news/newtips122.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us