Speedy Server Scripts
By Lincoln D. Stein
Last year, I wrote about the performance problems of traditional CGI scripts ("Server Scripts: Can they Keep Up?" Web Techniques, November 1996). The central problem, I concluded, was that CGI scripts run as separate processes. Each time the server needs to run a CGI script, it has to load it from disk and execute it. While this overhead may not be noticeable when you're first developing the script, it becomes a major headache on a production server with thousands of requests a minute. CGI scripts simply can't keep up with that kind of volume.
Briefly, the alternatives to CGI are:
- Turn the application into a client-side executable using Java, JavaScript, or ActiveX.
- Keep the CGI script running continuously as a separate process, avoiding the startup costs.
- Extend the server's functionality using a programmer's API or Java "servlets."
The first alternative is compelling because it scales up extremely well. The Web server simply sends the client-side executable down the wire, and the user's CPU does all the work. Increasing the number of simultaneous users from 10 to 100 adds no noticeable computational load to your server. Client-side executables have problems, however: No client-side technology allows you to support all combinations of browser and operating system, and there are tradeoffs between convenience and power. Java applets and JavaScript scripts will run on many browsers without modification, but their abilities are strictly limited for security reasons.