If you control the operating system and hardware where the application will be deployed, there are a number of changes you can make to improve performance. Some changes are generic and affect most applications, while some are application-specific. This chapter applies to most server systems running Java applications, including servlets, where you usually specify (or have specified to you) the underlying system, and where you have some control over tuning the system. Client and standalone Java programs are likely to benefit from this chapter only if you have some degree of control over the target system, but some tips in the chapter apply to all Java programs.
I don't cover operating-system and hardware tuning in any great detail, though I give basic tips on monitoring the system. More detailed information on Unix systems can be obtained from the excellent System Performance Tuning by Mike Loukides (O'Reilly). Another more specific book on Sun's Solaris operating system is Sun Performance and Tuning by Adrian Cockcroft and Richard Pettit (Prentice Hall). A couple of relevant Windows systems books are Windows NT Performance Monitoring, Benchmarking, and Tuning by Mark T. Edmead and Paul Hinsberg (New Riders) and Windows NT Applications: Measuring and Optimizing Performance by Paul Hinsberg (MacMillan Technical Publishing). Note that Macintoshes running OS X should include the Unix tools I mention in this chapter.
It is usually best to target the operating system and hardware as a last tuning choice. Tuning the application itself generally provides far more significant speedups than tuning the systems on which the application is running. Application tuning also tends to be easier (though buying more powerful hardware components is easier still and a valid choice for tuning). However, application and system tuning are actually complementary activities, so you can get speedups from tuning both the system and the application if you have the skills and resources.
Here are some general tips for tuning systems:
Constantly monitor the entire system with any monitoring tools available and keep records. This allows you to get a background usage pattern and also lets you compare the current situation with situations previously considered stable.
You should run offline work during off-hours only. This ensures that there is no extra load on the system when the users are executing online tasks, and enhances performance of both online and offline activities.
If you need to run extra tasks during the day, try to slot them into times with low user activity. Office activity usually peaks at 9:00 A.M. and 2:30 P.M. and has a low between noon and 1:00 P.M. or at shift changeovers. You should be able to determine the user-activity cycles appropriate to your system by examining the results of normal monitoring. The reduced conflict for system resources during periods of low activity improves performance.
You should specify timeouts for all processes under the control of your application (and others on the system, if possible) and terminate processes that have passed their timeout value.
Apply any partitioning available from the system to allocate determinate resources to your application. For example, you can specify disk partitions, memory segments, and even CPUs to be allocated to particular processes.