Java Performance Tuning, 2nd Ed.
Every developer has written a microbenchmark (a bit of code that does something 100-1000 times in a tight loop and measure the time it takes for the supposed "expensive operation") to try and prove an argument about which way is "more efficient" based on the execution time. The problem, is when running in a dynamic, managed environment like the 1.4.x JVM, there are more factors that you don't control than ones that you do, and it can be difficult to say whether one piece of code will be "more efficient" than another without testing with actual usage patterns. The second edition of Review of Java Performance Tuning provides substantial benchmarks (not just simple microbenchmarks) with thorough coverage of the JDK including loops, exceptions, strings, threading, and even underlying JVM improvements in the 1.4 VM. This book is one of a kind in its scope and completeness.
The Gory Details
The best part of this book is that it not only tells you how fast various standard Java operations are (sorting strings, dealing with exceptions, etc.), but he has kept all of the timing information from the previous edition of the book. This shows you how the VMs performance has changed from version 1.1.8 up to 1.4.0, and it's very clear that things are getting better. The author also breaks out the timing information for 3 different flavors of the 1.4.0 JVM: mixed interpreted/compiled mode (standard), server (with Hotspot), and interpreted mode only (no run time optimization applied).
Part 1 : Lies, Damn Lies and Statistics
The book starts off with three chapters of sage advice about the tools and process of profiling/tuning. Before you spend any time profiling, you have to have a process and a goal. Without setting goals, the tuning process will never end and it will likely never be successful.
The author outlines a general strategy that will give you a great starting point for your tuning task forces. Chapter 2 presents the profiling facilities that are available in the Java VM and how to interpret the results, while chapter 3 covers VM optimizations (different garbage collectors, memory allocation options) and compiler optimizations.
Part 2 : The Basics
Chapters 4-9 cover the nuts and bolts, code-level optimizations that you can implement. Chapter 4 discusses various object allocation tweaks including: lazy initialization, canonicalizing objects, and how to use the different types of references (Phantom, Soft, and Weak) to implement priority object pooling. Chapter 5 tells you more about handling Strings in Java that you ever wanted to know. Converting numbers (floats, decimals, etc) to Strings efficiently, string matching -- it's all here in gory detail with timings and sample code.
This chapter also shows the author's depth and maturity; when presenting his algorithm to convert integers to Strings, he notes that while his implementation previously beat the pants off of Sun's implementation, in 1.3.1/1.4.0 Sun implemented a change that now beats his code. He analyzes the new implementation, discusses why it's faster without losing face. That is just one of many gems in this updated edition of the book. Chapter 6 covers the cost of throwing and catching exceptions, passing parameters to methods and accessing variables of different scopes (instance vs. local) and different types (scalar vs. array). Chapter 7 covers loop optimization with a java bent. The author offers proof that an exception terminated loop, while bad programming style, can offer better performance than more accepted practices.
Chapter 8 covers IO, focusing in on using the proper flavor of java.io class (stream vs. reader, buffered vs. unbuffered) to achieve the best performance for a given situation. The author also covers performance issues with object serialization (used under the hood in most Java distributed computing mechanisms) in detail and wraps up the chapter with a 12 page discussion of how best to use the "new IO" package (java.nio) that was introduced with Java 1.4. Sadly, the author doesn't offer a detailed timing comparison of the 1.4 NIO API to the existing IO API. Chapter 9 covers Java's native sorting implementations and how to extend their framework for your specific application.
PART 3 : Threads, Distributed Computing and Other Topics
Chapters 10-14 covers a grab bag of topics, including threading, proper Collections use, distributed computing paradigms, and an optimization primer that covers full life cycle approaches to optimization. Chapter 10 does a great job of presenting threading, common threading pitfalls (deadlocks, race conditions), and how to solve them for optimal performance (e.g. proper scope of locks, etc).
Chapter 11 provides a wonderful discussion about one of the most powerful parts of the JDK, the Collections API. It includes detailed timings of using ArrayList vs. LinkedList when traversing and building collections. To close the chapter, the author discusses different object caching implementations and their individual performance results.
Chapter 12 gives some general optimization principles (with code samples) for speeding up distributed computing including techniques to minimize the amount of data transferred along with some more practical advice for designing web services and using JDBC.
Chapter 13 deals specifically with designing/architecting applications for performance. It discusses how performance should be addressed in each phase of the development cycle (analysis, design, development, deployment), and offers tips a checklist for your performance initiatives. The puzzling thing about this chapter is why it is presented at the end of the book instead of towards the front, with all of the other process-related material. It makes much more sense to put this material together up front.
Chapter 14 covers various hardware and network aspects that can impact application performance including: network topology, DNS lookups, and machine specs (CPU speed, RAM, disk).
PART 4 : J2EE Performance
Chapters 15-18 deal with performance specifically with the J2EE APIs: EJBs, JDBC, Servlets and JSPs. These chapters are essentially tips or suggested patterns (use coarse-grained EJBs, apply the Value Object pattern, etc) instead of very low-level performance tips and metrics provided in earlier chapters. You could say that the author is getting lazy, but the truth is that due to huge number of combinations of appserver/database vendor combinations, it would be very difficult to establish a meaningful performance baseline without a large testbed.
Chapter 15 is a reiteration of Chapter 1, Tuning Strategy, re-tooled with a J2EE focus. The author reiterates that a good testing strategy determines what to measure, how to measure it, and what the expectations are. From here, the author presents possible solutions including load balancing. This chapter also contains about 1.5 pages about tuning JMS, which seems to have been added to be J2EE 1.3 acronym compliant.
Chapter 16 provides excellent information about JDBC performance strategies. The author presents a proxy implementation to capture accurate profiling data and minimize changes to your code once the profiling effort is over. The author also covers data caching, batch processing and how the different transaction levels can affect JDBC performance.
Chapter 17 covers JSPs and servlets, with very little earth shattering information. The author presents tips such as consider GZipping the content before returning it to the client, and minimize custom tags. This chapter is easily the weakest section of the book: Admittedly, it's difficult to optimize JSPs since much of the actual running code is produced by the interpreter/compiler, but this chapter either needs to be beefed up or dropped from future editions.
Finally, chapter 18 provides a design/architecture-time approach towards EJB performance. The author presents standard EJB patterns that lend themselves towards squeezing greater performance out of the often maligned EJB. The patterns include: data access object, page iterator, service locator, message facade, and others. Again, there's nothing earth shattering in this chapter. Chapter 19 is list of resources with links to articles, books and profiling/optimizing projects and products.
What's Bad?
Since the book has been published, the 1.4.1 VM has been released with the much anticipated concurrent garbage collector. The author mentions that he received an early version of 1.4.1 from Sun to test with. However, the text doesn't state that he used the concurrent garbage collector, so the performance of this new feature isn't indicated by this text.
The J2EE performance chapters aren't as strong as the J2SE chapters. After seeing the statistics and extensive code samples of the J2SE sections, I expected a similar treatment for J2EE. Many of the J2SE performance practices still apply for J2EE (serialization most notably, since that his how EJB, JMS, and RMI ship method parameters/results across the wire), but it would be useful to fortify these chapters with actual performance metrics.
So What's In It For Me?
This book is indispensable for the architect drafting the performance requirements/testing process, and contains sage advice for the programmer as well. It's the most up to date publication dealing specifically with performance of Java applications, and is a one-of-a-kind resource.
You can purchase Java Performance Tuning, 2nd Edition from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
I just watched a live report on CNN. A statue of Saddam Hussein (D-Baghdad) in central Baghdad has been torn down by Iraqi civilians and American soldiers. Saddam's head was last seen being dragged through the streets of Baghead, ridden by jubilant Iraqis. Even if you are a whiny eurotash America hater, there was no denying his murderous exploits. Truly an (honorary) French icon.
Optimize this!
We French maintain our stance. France run by Saxons, Germans, or anyone else is better than dying to defend ourselves. Vive la France!
really makes you European appeaser fags look so utterly stupid doesn't it?
I got the 14th post you bastards.
Yes, this is the 14th post that has been contributed to this story.
Hi George, this is TASHA.
It's a shame the French didn't get involved in the war early on. They could have really helped us teach the Iraqis how best to surrender with their experience in such matters.
Yo Yo move out the way we got Missy Elliot commin' through Girl that is Missy Elliot, she lost alot of weight I heard she eats one crack a day
Girl well i heard the bitch was married to Tim and started fuckin with Trina Well i heard the bitch got hit by three zebras and a monkey i cant stand the bitch no way
When i walk up in the piece I aint goatta even speak Im a bad mamma jamma god damnit muthafucka
You aint goatta like me I aint stut'n these hoes need o talk wat ya kno Stop talkin bout who im stickin im lickin Just mad it aint yours I kno yall poor yall broke
Yall jobs just hangin up cloaks step to me get burnt like toast Muthafuckas adois amigos Ah ah Pose pose I dont brag i mostly boast From the VA to the LA coast Izzy Gizzy Lizzy Go
Musi ques I sews on bew I pues a twos on que zat Pue zoo My kizzer
pous zigga ay zee Its all kizza its always like its all kizza its always like Na Zound wa zee wa zoom zoom zee
When i pull up in my whip Bitches wanna talk shit Im drivin im blindin them upside these muthafuckass did you see it Im drippin these curves skurrt did ya heard
I lovas my fellas my furs Ah i fly like a bird Chickenheads on the prowl Who u tryda to fuck now Now u aint gettin loud better calm down before i smack your ass down i need my drum bass high
has to be my snare strings horn yes i need myTim sound right left Izzy kizzy look at him
Musi ques I sews on bew I pues a twos on que zat Pue zoo My kizzer pous zigga e zay
Its all kizze its always like its all kizze its always like Na Zound wa zee wa zoom zoom zee
Now i dont go out my house shorty you just waiting to see Who imma roll up in the club with and report that next week Just wanna see who i am or sniffin some coke i kno bythe time i finish this line imma hear this on the radio
Once upon a time in college park Where the live life fast and they scared of dark There was a little nigga by the name of Cris Nobody paid him any mind no one gave a shit Knowing he could rap no one lift ahand So he went about his bidness And devised a plan Made a CD then he hit the block
50 thousand sold 7 dollars a pop hold the phone three years later stepped out the swamp with ten and a half gators Now all around the world on the microphone He leaves your boobs smelling like burrberry cologne Still ridin' the chrome Got bitches in the kitchen never home alone And he's on the grind Please let me know if he's on your mind And respect you'll gimme
Ludacris i look lord like Timmy Had to clear these rumors I got a headache and its not a tumor Get up on my lap get my head tucked tight Sprayed so i never let the bed bugs bite
I'm hard to the core Core to the rotten You jump down turn around pick a bail a cotten
Musi ques I sews on bew I pues a twos on que zat Pue zoo My kizzer
pous zigga ay zee Its all kizza its always like its all kizza its always like Na Zound wa zee wa zoom zoom zee
Yo straight up, Missy killed that shit tonight fo'real I know I don't really care bout her being pregnant by Micheal Jackson You know what we should do?
We should go get her album when it come out, what she gon do she gon do, shh Hi Missy! Hi Missy?! Wusup foos! You think I aint knowin yall broke Milli Vanilli Jay Jay fan wannabes aint over here gossiping bout me?
Yo how bout you buff these Pumas for 20 cents so your lights wont get cut off You soggy breasts, cow stomachs Yo take those baby GAP shirts off, too You just mad cuz Payless ran out of plastic pumps for the after party Yo by the way, go get my album Damn!
Musi ques I sews on bews I pues a twos on que zat Pue zoo My kizzer Pous zigga ay zee
Said like a true pussy!
How the fuck did this get a score of 1
and QUIT MODDING the 'LEARN C' trollers with 1
I have Limewire.org and DVarchive already. I know about Moneydance, which might be popular someday. Freenet might work well enough someday to qualify. Anything else? If you got 'em, post 'em.