20.3 Programming

Team-Fly    

 
Webmaster in a Nutshell, 3rd Edition
By Robert Eckstein, Stephen Spainhour
Table of Contents
Chapter 20.  Web Performance

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 

20.3.2 Logging

Running a system call tracer may also show you that you are doing too much logging. You might be surprised to know how much debugging code gets left on by accident in a production environment. Logging from Java can be especially slow, because the VM may convert each byte from Unicode to ASCII before writing it to the log file.

20.3.3 Compressing Files

Consider using gzip compression on static files. If you compress your files on the server side with gzip and end them with the .gz suffix, most browsers will now automatically detect that and decompress the files. This can be a huge performance boost for users on slow connections like modems, because it can reduce by more than half the amount of data they need to download.


Team-Fly    
Top


Webmaster in a Nutshell
Webmaster in a Nutshell, Third Edition
ISBN: 0596003579
EAN: 2147483647
Year: 2002
Pages: 412

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net