Building High-Performance
Applications and Servers in Java:
An Experiential Study
By: Sandeep K. Singhal
IBM T.J. Watson Research Center
Binh Q. Nguyen, Richard Redpath, Michael Fraenkel, Jimmy Nguyen
IBM Software Solutions
Abstract
The Java programming language is rapidly becoming the language
of choice for developing dynamic content for the Internet. The
language's popularity has arisen from its portability, ease-of-use,
and integration with HTML. Java is being used to enable animation
on Web pages, to dynamically select and format Web page content
at Web servers, and to provide client-side user input checking
as a front-end to transaction-oriented applications. However,
with a few exceptions, Java has not been used to develop applications
and servers that demand high performance or throughput.
In this paper, we describe techniques for improving the performance
of Java code and enabling the development of high-throughput applications
and servers. We show that Java code can be easily optimized to
achieve performance that is comparable to code developed in traditional
languages such as C or C++. We base these results on our experience
in developing the InVerse (Interactive Universe) server in Java.
Caveats
Practitioners who read or use the results in this paper should
bear some things in mind:
- We have only performed tests on Sun's 1.0.2 Java class
library and virtual machine on one platform. Other hardware,
Java virtual machines, and class library implementations are unlikely
to exhibit identical behavior, though we expect that many of the
described results are universally applicable.
- The numbers presented in this paper were generated using a
millisecond-resolution clock that takes up to 0.5 milliseconds
to execute. As a result, our numbers may exhibit a relatively
large margin of error. Differences of 10-20% can safely be
attributed to statistical error, garbage collection effects, or
clock resolution. We have therefore focused our attention on performance
differences that have greater significance.
- This study is by no means exhaustive. It represents analyses
performed to support a particular server application. Though
we expect the results to be of general use, we have not assessed
whether the operations common in our application are equally common
to other applications.
Conclusions: Improving Java Application Performance
Java application performance can be improved by applying the following
optimizations:
- Eliminate synchronization in application code. Implement unsynchronized
versions of Java library classes and use those versions when the
application is single-threaded or data structure access controlled
by design.
- Determine the most common operations performed on standard
Java classes and re-implement those classes to speed up those
common cases.
- Merge Java classes when interactions can be optimized.
- Where errors are rare, avoid checking for errors and instead
catch exceptions (ArrayIndexOutOfBoundException, ClassCastException,
etc.) generated by the Java run-time.
- Avoid creating temporary objects and, where possible, re-use
objects by providing a reinitialize() operation.
- Limit variable reads and writes where possible. Cache class
static variables and instance variables in method stack variables
when possible because the latter provide faster access. Reverse
the order of common loops to count down to zero instead of counting
up to a variable limit.
Download complete paper
This paper is in PDF format and can be viewed and printed with
Adobe's Acrobat(TM) Reader.
A free copy of the reader is available
from Adobe.
|
JavaTM is a trademark of Sun Microsystems, Inc.
Other companies, products, and service names may be trademarks or service marks of others.
Copyright
Trademark
|