Programming

Like HTML authors, some programmers do too much and want to use the latest thing. Distributed object schemes like CORBA and EJBs are complex and have poor performance, but are often preferred over CGI and servlets because they’re more challenging. CGI and servlets may be boring, but they work quite well.

Unbuffered Reads and Writes

A very common performance problem is the use of unbuffered reads and writes. You can diagnose this problem by examining which system calls are being executed and what the parameters to those calls are, via a system call tracing utility such as truss on Solaris or strace on Linux. Other such utilities include ktrace and par. Shared library calls can be seen using sotruss.

These tools are especially useful for finding out that an application is doing single byte reads or writes, which is terribly inefficient. In Java, the single-byte read/write problem is easily fixed by using buffered readers and writers rather than single-byte I/O. If you run

% truss -t read,write -s\!all -p 
                  <process id>

You want to see fast buffered 8K reads, like this:

read(49, " B\r\n T R 0 8 0 6 5 9".., 8192) = 8192 
read(49, " J".., 8192) = 8192 
read(49, " 2 4 9 B D ".., 8192) = 8192 
read(49, " 0 0 3 2 9 . 8 9 0 0 0 0".., 8192) = 8192 
read(49, " . 0 0 R ".., 8192) = 8192 
read(49, " B\r\n T R 0 8".., 8192) = 8192 
read(49, " ".., 8192) = 8192 
read(49, " 4 4 1 3 2 4 9 B ".., 8192) = 8192 
read(49, " 0 0 0 2 4 5 6 1 5 . 0 3".., 8192) = 8192

You do not want to see one-byte ...

Get Webmaster in a Nutshell, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.