Maximizing Performance and Scalability with IBM WebSphere

Web Tier Performance

The Web tier refers to all Web containers, Web servers, and components. This includes Java components such as

Avoid Constant Use of Large Session Objects

As you've learned in previous chapters, sessions are a key element of any Web-based WebSphere application environment. It's possible to overuse sessions by filling them up with unnecessary information, not releasing unwanted elements after use, or using them for incorrect purposes. The effect is exaggerated when session persistence is used to achieve additional levels of redundancy.

Essentially, in the case of persisting the session object because accessing the session object requires serialization and deserialization for each update and read, respectively (to and from the session persistence layer), the J2EE application incurs significant overhead if sessions become too large. This impact is further realized if you use persistent sessions, in which you persist sessions to a database in order to gain availability.

To summarize,

Performance and scalability benefit:

1

Implementation complexity:

3

Invalidate HTTP Sessions When They Aren't Required

HTTP sessions are often used in Web applications. One of the common implementation errors that developers make is not cleaning up sessions that are no longer required. This is a side effect of the thought that because you don't need to manage memory in Java (unlike in C, C++, and so on), you don't need to clear off unused objects.

Because WebSphere can maintain only a certain number of sessions at any one time in memory (a configurable counter), and the fact that there's a finite amount of memory available per application Java Virtual Machine (JVM), you'll want to ensure that you provide your JVM and other application threads the maximum amount of memory available or required by them. By also not invalidating the HTTP sessions forcefully , the JVM garbage collection will spend more time clearing out heap space for other application threads, which impacts over-all JVM performance.

To summarize,

Performance and scalability benefit:

3

Implementation complexity:

2

Use the init() Servlet Method if doGet() and doPost() Aren't Required

Basic servlets consist of the init() , doGet() , and doPost() methods , which are used for different purposes when a servlet is called. The init() method is called each time a call to initialize a servlet is made, whereas the doGet() and doPost() methods are only called when those types of HTTP transactions are requested through the HTTP headers in a user request.

Quite often, a servlet isn't required to perform any function based on input. For this reason, there's no need to use a doGet() method call ”this will incur overhead that isn't required. Consider placing heavy or expensive transactions in the init() method instead of in the doGet() and doPost() methods. A classic example is to place bindings to data sources in the init() method, which will alleviate a rebind on each doGet() or doPost() method call. This will increase performance within your application.

To summarize, question the use of doGet() and doPost() method usage in servlets if the servlets aren't expecting any input but are required to return information.

Performance and scalability benefit:

3

Implementation complexity:

2

Use <jsp: usebean ()> Carefully

This JSP tag allows developers to directly call a JavaBean from within the JSP code. Quite often, developers use this approach in JSP pages to fill small variables or values into JSP output such as simple integers (e.g., account balances ).

This tag, however, will create a new instance of the specific JavaBean if the JavaBean object doesn't already exist. Creating the new bean is an expensive JVM operation and, unless required, it should be used only to obtain a reference to an existing Java object.

Performance and scalability benefit:

3

Implementation complexity:

2

Don't Use the Single-Threaded Model with Servlets

A design approach exists with servlets that allows the servlets to be developed using a single-threaded model. This approach is sometimes used to ensure the protection of specific variables within a servlet's context; however, it does introduce a performance and scalability implication by limiting the number of servlet threads that can be running concurrently.

If specific variables need to be managed per client thread, consider using the session object for small variables or other forms of data storage, such as memory caches and/or databases.

Performance and scalability benefit:

2

Implementation complexity:

2

Категории