ITworld.com
  Search  
ITworld Home Page ITworld Webcasts ITworld White Papers ITworld Newsletters ITworld News ITworld Topics Careers ITworld Voices ITwhirled Changing the way you view IT
Learn to Performance Tune Your Java Programs
JAVA TUTOR --- 08/28/2002

Adrian Cockcroft

Q: How can I find out how to do performance tuning for Java programs?

A: I asked around and found a useful Web site with information. I also have a new Java percollator graphing program that I'm tuning that includes a useful class to help measure its performance. I've been trying out the profiler feature of Java WorkShop 2.0 on it as well. 

On this topic

Almost two years ago I figured out Java enough to put together a very simple performance graphing applet. This summer I helped a student intern rewrite and extend it. The result is a much more useful tool that runs as both an applet and as an application, and which browses the files generated by my percollator Web server performance monitor script. When graphing large amounts of data the program can slow down, so code was added to time critical operations and report a summary. Because this is a useful code fragment in itself, that's where I'll start.

The Metrognome Class
I wanted a simple object that measured a time interval multiple times, then generated a summary of the results. The name is a joke, as it's a kind of small helpful personalized metronome. The main design idea was to create a separate object that had a simple collection interface but could also be upgraded and extended without changing the interface. That way a program using the Metrognome class could be instrumented in more detail by just replacing the class. No recompilation or interface changes should be necessary.

A Metrognome is constructed by giving it a text label that identifies it.

Metrognome redrawTimer = new Metrognome("Display redraw");

At some point in the code, let's say during the paint method that redraws the display, we call the start method then call the stop method.

paint() {
redrawTimer.start(); // lots of display update code redrawTimer.stop(); }

The Metrognome is now collecting the duration of all display updates. Somewhere else in the code we need to have a way to show the results. The getSummary method returns a String that can be displayed in a GUI, written on exit to the Java console or whatever else you like. Some individual performance data can also be read from the Metrognome and displayed, but it is easy to update the contents of the String if a more sophisticated Metrognome is used.

The summary string shows the label, count, and min/mean/max times in seconds. For example,

"Display redraw: count= 5 Latency(s) min= 0.017 mean= 0.029 max= 0.041"

More ideas
As usual I have more ideas than time to implement them. Some possibilities for extending the Metrognome class, without changing the interface to the rest of the program, might include:

  • Accumulate time buckets to produce a histogram of the time distribution
  • Log a time stamped record to a buffer on each start
  • Update the record on each stop with the duration
  • Log the records somewhere
  • Make all the Metrognomes share one big buffer -- access locking would be needed
  • Wait until a few times have been counted then compare against the mean and deviation to report on abnormally large delays
  • Open an RMI connection to report back to a central data collection server

 

Adrian started out as a software engineer and UNIX system administrator and was one of the first customers of Sun in the UK circa 1984. In 1988 he joined Sun UK as a Systems Engineer and built a reputation as a specialist in SPARC and performance- related issues. In 1993 Adrian transferred to Sun's corporate headquarters in the USA to work for SMCC Technical Product Marketing. A major function of this group is to create the technical information required to support Sun's Systems Engineers on a worldwide basis. He now works in the Server Division of SMCC, and in April 1996 relocated back to the UK, teleworking to California. Adrian is the author of Sun Performance and Tuning: SPARC and Solaris, published by Sun Microsystems Press/PTR Prentice Hall.



Advertisements
Sponsored links
KODAK i1400 Series Scanners stand up to the challenge
Top 5 Reasons to Combine App Performance and Security
Locate Hidden Software on business PCs with this free tool
Bring harmony to your mix of UNIX-Linux-Windows computing environments
 Home   Newsletters  JAVA TUTOR
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   Industry Standard   Infoworld   ITworld  
JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

DEMO   IDG Connect   IDG Knowledge Hub   IDG TechNetwork   IDG World Expo  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.