J2EE takes the hassle out of distributed programming, but there's a catch. Although you no longer have to contend with such low-level issues as threading, synchronization, or persistence, you also relinquish control of key architectural considerations such as load balancing and scaling. Leaving these taskswhich strongly impact performanceto the EJB container can lead to performance problems, because ultimately no third-party software can know your application as well as you do.
Performance problems manifest themselves in many ways:
- JSPs take too long to load.
- Search screens take minutes to show results or never return at all.
- The user interface does not respond, and users click furiously but to no discernible effect.
- At peak times, the server fails unexpectedly due to "out of memory" errors, locked database tables, and connection timeouts.
- Your previously reliable nightly batch processes become strangely fragile and take longer to run.
The day-to-day operation of the business is being impacted and the extra hardware you want isn't going to arrive anytime soon. You need to diagnose the problem and implement the fixes. A few basic techniquesDBMS optimization, caching, threading, fine-grained transaction control, deferred processing, and EJB restructuringcan help you take back control of your application to meet your performance targets.
Design with Performance in Mind
Unless you consider and factor performance into your user interfaces, designs, and development processes up front (including testing early and often), you'll likely hit problems sooner or later. The key to good performance is to understand your performance goals up front. Understand the number of concurrent users, target response times, usage patterns, and data growth. Know how your application is going to be used: which parts of the system are session-based and which are non-session or batch-based. That way you can structure your architecture to meet your needs.
Focus on What's Important to the Business
Sometimes the performance aspects of a system are left to the end of the project. Developers just don't have time to consider response times when speed of delivery and functionality are the pressing goals. Performance bottlenecks must be systematically identified and solved, which is no light task. The later in the development life cycle you address them, the more expensive they become to fix.
Small optimizations (like turning logging down) can yield huge gains, whereas others can have minuscule effects. The key to tackling bottlenecks is to prioritize and focus on the areas of your code that will yield the biggest return for your time investment. Focus on frequently used parts of the code, the parts critical to your business. Gather accurate performance metrics and use repeatable test cases to validate against your performance targets.