home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeWebmaster in a Nutshell, 3rd EditionSearch this book

20.3. 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.

20.3.1. 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 unbuffered reads, like this:

read(49, " C", 1) = 1 
read(49, " C", 1) = 1 
read(49, " ", 1) = 1 
read(49, " 0", 1) = 1 
read(49, " 2", 1) = 1 
read(49, " 3", 1) = 1 
read(49, " 0", 1) = 1 
read(49, " 0", 1) = 1 
read(49, " 7", 1) = 1 
read(49, " 5", 1) = 1 
read(49, " 6", 1) = 1 
read(49, " ", 1) = 1 
read(49, " 0", 1) = 1 
read(49, "\r", 1) = 1


Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.