Enhance Web Performance

To enhance the performance of a web site, software engineers usually perform code optimization and cache control. Code optimization involves removing unnecessary data, streamlining business logic and source code. Cache control involves storing commonly accessed instructions in fast accessed medium such as RAM.

Usually code optimization and cache control is a manual process for the developer to perform before deployment. This is a tedious and time-consuming process where the developer and tester are required to locate the slow pages, scan through the code to streamline the business logic and the source code, and cut down unnecessary code and logic. Then the engineer needs to identify frequently accessed objects and develops caching solutions for them.

This article describes MadCaching, a dynamic server-side cache control solution for Struts and Tiles programmers. With Struts and Tiles, web caching can be turned off and on with a few configuration steps, however code optimization continues to remain a manual process.

Struts and Tiles Background

Struts is a Controller framework based on the Model-View-Controller design pattern (Figure 1). The Controller accepts incoming requests and forwards them to the appropriate handler. The handler then calls the appropriate Model. The Model is responsible for the business logic and state. The handler sends the forwarded information back to the controller to display the View. The View sends the HTML page back to the response. Refer to http://struts.apache.org for more information on Struts.

Figure 1

Tiles framework allows templating and componentization of the View. Templating separates HTML page into several different portions called tiles. Figure 2 illustrates a HTML page separate into tiles: header, menu, body, and footer.

Figure 2

Componentization allows the tiles to be reused in other templates. Refer to http://struts.apache.org/userGuide/dev_tiles.html for more information about Tiles. The Tile Resources section of this web page is a good start.

The MadCaching Solution

MadCaching is an extension of Tile framework. It provides the ability to enable or disable caching for a tile on demand. A designer or coder does not have to worry about caching during implementation. He/she can program tiles as normal. On deployment, with a few configuration changes to the web.xml and struts-config.xml file, he/she can take advantage the build-in caching module.

In effect, MadCaching eliminates the need for the designer or coder to implement a customized cache control. The use cases corresponding to MadCaching is illustrated in Figure 3. The User involvement in MadCaching is transparent. In user perspective, the web experience is the same (except for access time improvement). A User request a page (with cache tiles.) MadCaching initiates tile caching. The Performance Configuration Engineer specifies the tiles that can be cached and the parameters that identify uniqueness.

Figure 3

We will follow the MadCaching Sample web application to better illustrate how MadCaching works. Figure 4 gives an overview of Performance Configuration Engineer and User interactions with MadCaching.

Figure 4

In Step 1, The Performance Configuration Engineer initiates the caching specification process by open the MadCaching Manager (Figure 5).

Figure 5

In Step 2, the Performance Configuration Engineer clicks on the ?Capture On? link initiates the tile capture process. After capture, the tiles of visiting pages (step 3) are stored in a captured list along with their request parameters, page attributes, request attributes, session attributes, and application attributes in use for the pages (step 4).

On step 5, the Performance Configuration Engineer selects a tile, in this example, ?sum.demo? (Figure 6). The right frame displays the caching information for ?sum.demo?. The Performance Configuration Engineer turns on the caching by checking on the ?Enable Tile Caching? checkbox and selects the ?increment? and ?times? parameters as the unique keys for the tile. Then he clicks submit to apply the tile caching changes.

Figure 6

After the Performance Configuration Engineer finishes enabling caching for the application, the user visiting the web pages (Step 6-12) will experience a slight performance lags for the first time. Subsequence visits to the pages render the tiles from cache.

Other MadCaching Manager Functions

  • Navigation Menu

    Capture OffTurns the tile capture off
    Capture ResetClears the tile capture list
    Update CaptureRefreshes the frame to update the list of capture tiles.
  • Advance Settings

    Selecting ?Advance Setting Show? expands a list of configuration fields. These fields are:

    Repository NameTurns the tile capture off
    Repository FactoryFactory class for the Cache Repository.
    Key FactoryKey factory class to generate key for the Cache Repository.
  • ?Save Tile Changes? button saves the tile definitions and the tile caching information into a new tile definition file. Essentially, MadCaching reads the original tile definition file, and adds the caching information to generate the new file. The Performance Configuration Engineer can replace the tile definition file with the new file to deploy Tiles with caching.


This product includes software developed by the Apache Software Foundation (http://www.apache.org/).