Java on Solaris 7 Developer's Guide

I/O

The biggest and most common performance problem in Java applications is often inefficient I/O. Therefore, I/O issues should generally be the first thing to look at when performance-tuning a Java application. Fixing these problems often results in greater performance gains than all the other possible optimizations combined. It is not unusual to see a speed improvement of one order of magnitude achieved by using efficient I/O techniques.

If an application performs a significant amount of I/O, then it is a candidate for I/O performance tuning. This conclusion can be confirmed by profiling the application. To learn how to profile an application, you can use the Java WorkShop (JWS) product. JWS can be obtained from:

http://www.sun.com/workshop

Select Help->Help Contents, and click on Profiling Projects. This example involves running a benchmark test reading a 150,000-line file using four different methods:

  1. DataInputStream.readLine() alone (unbuffered).

  2. DataInputStream.readLine() with a BufferedInputStream underneath, which has a buffer size of 2048 bytes.

  3. BufferedReader.readline() with a buffer size of 8192 bytes.

  4. BufferedFileReader(fileName).

The results were as follows: (times in seconds) :

DataInputStream: 178.740
DataInputStream(BufferedInputStream): 21.559
BufferedReader 11.150
BufferedFileReader  6.991

Note that methods 1 and 2 do not properly handle Unicode characters, while methods 3 and 4 handle them correctly. This makes methods 1 and 2 unacceptable for most product uses. Also, DataInputStream.readLine() is deprecated as of JDK 1.1. Method 1 is used in JWS and other programs.

Another way to spot Solaris I/O problems is to use truss(1) to look for read(1) and write(1) system calls.