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: Threading Essentials course
Tips September 2003
Get rid of your performance problems and memory leaks!
Get rid of your performance problems and memory leaks!
Back to newsletter 034 contents
JMS Application Architectures (Page last updated August 2003, Added 2003-09-30, Author Roland Barcia, Publisher TheServerSide). Tips:
- RPC calls provide better response for synchronous calls; JMS calls are really for asynchronous calls, not pseudo-syncrhonous calls where the sender waits for the reply regardless of the calling mechanism.
- The best way to move a use case to asynchronous is by convincing the user that he or she can wait an extra second for the notification event or email.
- JMS consumers should use the re-delivered count field on the message descriptor to ensure that a message is not processed repeatedly.
- Asynchronous messaging designs can use more transactions than synchronous RPC calls.
- Deciding on an asynchronous user initiated call: Does the user need to know the result in the same session as the invocation? Can they wait 2 minutes for an email? Can the user check the status?
Hyperthreading Java (Page last updated August 2003, Added 2003-09-30, Author Paul Bemowski, Publisher JavaDevelopersJournal). Tips:
- A cache miss will require the processor to make a request to main memory, durng which the majority of the processor's resources remain idle, (SMT systems use this slice of time to execute the operations of another on-chip thread context).
- A threaded benchmark test bed should be able to execute multiple operations across n threads, observing the total throughput of operations per unit of time for a run.
- Single-threaded applications will see almost no performance gain from multi-CPU and hyper-threaded systems.
- [Article includes four CPU intensive benchmarks: Gaussian Elimination (Floating point intensive); Calculation of 2000! (Integer intensive); 150K calculations of Math.tan() (Floating point, mixed stack); Prime number search (BigInteger operations)].
- IBM JVMs (at 1.4.x) seem to perform better and scale better at CPU intensive tasks than Sun JVMs.
Fast math with JNI (Page last updated August 2003, Added 2003-09-30, Author Jeff S. Smith, Publisher JavaWorld). Tips:
- The math routines in 1.4x are several times slower than the corresponding routines in 1.3.1.
- A new math package, StrictMath, in J2SE 1.4 guarantees identical math calculations across all platforms at the expense of execution speed.
- [Article describes how to use JNI to call a faster native library for maths functions].
Referencing objects (Page last updated August 2003, Added 2003-09-30, Author Jack Shirazi Kirk Pepperdine, Publisher IBM). Tips:
- The easiest way to identify unintentionally retained objects is by using a profiler with the abilities to snapshot the heap, compare object numbers between snapshots, track objects, find back references to objects, and force garbage collections.
- With an appropriate profiler, the procedure to follow to identify unintentionally retained objects is: Wait until the application has reached a steady state; Force a garbage collection, and take an object snapshot of the heap; Do some work; Force another garbage collection and then take a second object snapshot of the heap; Compare the two snapshots to see which objects have increased in number from the first snapshot to the next to identify those newly created objects that are being unintentionally retained by the application; Track back-references to find which objects are referencing the unintentionally retained objects, until you reach the root object that is causing the problem.
- Correctly scoping variables is a best practice, and enables the JVM to interact optimally with the garbage collector.
- Incorrectly scoping variables can lead to unintentionally retained objects.
- Explicit nulling of references can improve performance in some unusual cases; and can make performance worse in other unusual cases.
BufferedImage as Good as Butter (Page last updated August 2003, Added 2003-09-30, Author Chet Haase, Publisher java.net). Tips:
- Use BufferedImage for most, if not all, of your image needs.
- new BufferedImage(int width, int height, int type) is a synchronous call that provides an image, but note that this image is not optimal - use GraphicsConfiguration.createCompatibleImage for optimal performing images.
- GraphicsConfiguration.createCompatibleImage(int width, int height) returns an opaque BufferedImage in the same format as the screen which means that operations to/from the screen or other compatible images should be optimized (and sometimes hardware accelerated).
BufferedImage as Good as Butter II (Page last updated August 2003, Added 2003-09-30, Author Chet Haase, Publisher java.net). Tips:
- In 1.4.x there is only one image type that guarantees to use any acceleration available on the runtime platform: VolatileImage.
- VolatileImages are stashed in accelerated memory (such as VRAM on Windows, or an accelerated pixmap on Unix) and then perform rendering operations to and from that image using any available hardware acceleration.
- VolatileImages work well for things like back buffers where you want to render to them frequently and copy from them as fast as possible.
- For your average image, managing a VolatileImage can be tiresome since you have to make sure it's there before and after you use it.
- For images like icons, sprites, etc, which you really only write to once or occasionally, but from which you would like to copy often, there are managed Images, which are cached internally, created using one of: GraphicsConfiguration.createCompatibleImage(w, h); GraphicsConfiguration.createCompatibleImage(w, h, transparency); Component.createImage(w, h); Toolkit.getImage(...); new ImageImage(...).getImage().
- Not all image types that you get from "managed" image creators are acceleratable in 1.4.x; For example, if you create an image with the flag Transparency.TRANSLUCENT then it is not currently (1.4.x) accelerated and you end up going through software rendering loops regardless. From 1.5 almost all images should be accelerated.
- There are at least 3 situations in which you might want to us a VolatileImage versus a Managed Image: you want to change the contents often; you want to take advantage of hardware acceleration for rendering operations TO the image; you want more control over how and when the image gets accelerated.
Profiling the profilers (Page last updated August 2003, Added 2003-09-30, Author Laurence Vanhelsuwé , Publisher JavaWorld). Tips:
- [Article compares three currently available commercial profilers, including showcasing some features: Borland's Optimizeit Suite; Quest Software's JProbe Suite; ej-technologies' JProfiler].
Living with [Abstraction] Leaks (Page last updated July 2003, Added 2003-09-30, Author Craig Castelaz, Publisher java.net). Tips:
- Systems that are clear and general tend to have inadequate performance.
- Performance is often improved at the expense of generality.
- A given query issued using SQL may be thousands of times slower than a logically equivalent query, depending upon how the WHERE clause is written.
- Some people hold that it is fundamentally impossible to abstract resources and still maintain good performance. If this is true, then all performance tuning is a balancing act between better performance and better abstraction.
- [Article has a fascinating discussion of the design choices available in creating interfaces with more or less flexibility according to performance tuning needs].
Performance of Java Compilers (Page last updated July 2003, Added 2003-09-30, Author Haralambos Marmanis, Publisher JDJ). Tips:
- Performance problems can be categorized in order of importance as: System architecture; Algorithm selection; Code implementation; System configuration; System infrastructure.
- The performance of the whole is equal to the performance of its parts plus the overhead of the interaction between the parts.
- The right choice, at the micro level of the code, can squeeze out speed without making the code more complicated or error prone.
- Global performance excellence stems from a global enforcement of best practices, i.e., fast implementations throughout the code.
- [Article compares a number of benchmarks for several Sun JVMs and the IBM Jikes JVM].
- String.equalsIgnoreCase is a lot faster than String.equals when the majority of the compared data have different lengths because equalsIgnoreCase first checks the length of the two strings.
- Mathematical functions are two orders of magnitude faster with Jikes than with any of the Sun JVMs.
- Encryption-related methods in the Sun 1.4.x JVMs are an order of magnitude faster than the same methods in Sun 1.3.1.
- Different JVMs can be up two orders of magnitude slower (or faster) at different types of processing tasks.
Optimizing the Client/Server Communication for Mobile Applications, Part 1 (Page last updated July 2003, Added 2003-09-30, Author Forum Nokia, Publisher Nokia). Tips:
- With J2ME technology, you should expect long latency periods along with a limited bandwidth, as well as disconnected modes of operation.
- Binary message format guarantees the highest efficiency.
- XML-based message format (such as SOAP), offers maximum portability and readability, but performs extremely poorly, particularly with mobile devices due to the limited bandwidth and processing power that they have available.
- You can use a proxy server to handle optimal client/server messaging protocol while maintaining compatibility with other servers. The proxy server translates between efficient messaging formats for the J2ME application and other formats.
Back to newsletter 034 contents
Last Updated: 2020-09-28
Copyright © 2000-2020 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.
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us