Download NCache Now!

LIVE Product Demos

Sign-up Now

Short Product Videos

Watch Now!

Contact Us

Follow Us

 DiggLinked InTwitterYou Tube

Improve JavaServer Pages Performance with Caching

JavaServer Pages (JSP) has become a really popular choice for developing high-transaction, web applications. The reasons are simple. JSP is based on Java and is therefore platform independent. It helps maintain complex, information-rich, dynamic web applications and extend existing systems. Further Java IDEs like Eclipse and NetBeans have come a long way and they help speed up enterprise development quite a bit.

The Problem: JSP Servlets Performance Bottlenecks

This popularity of JSP has meant that it is being used quite frequently in developing high-traffic web apps. And, this is causing performance bottlenecks as you try to add more users and transaction load on your JSP application. Although, JSP application can scale very nicely to multiple web servers, the database server cannot.

As a result, your JSP application response time become very slow as you add more users and transaction load. And, this can cause you to lose revenue due to unhappy customers.


Figure 1: Database bottleneck in enterprise JSP applications

The Solution: Distributed Caching

The main reason for the database becoming a bottleneck is that while you can add more and more servers to the JSP application server farm, you cannot do the same at the database tier. This results in limited scalability at the data tier. The solution to this is simple. You can remove these JSP Servlets performance bottlenecks by using an enterprise-level in-memory distributed cache for storing the frequently used data.

Think of a distributed cache as an in-memory database that can scale linearly to multiple servers and therefore never has the performance bottlenecks. However, it is not a replacement of your database which is the master record of your data. It is merely used to store frequently used data temporarily.

The following illustration shows how you can use a distributed cache to achieve a considerable performance boost.


<%@page import="com.alachisoft.ncache.web.caching.*" %>

String cacheId = "mycache";
Cache _cache;

//Initializing the cache object

     _cache = NCache.initializeCache(cacheId);
Catch (Exception e){}
//Adding key (cache item name) and val (object) into the cache

_cache.add(key, val, null, Cache.NoAbsoluteExpiration,
Cache.NoSlidingExpiration, CacheItemPriority.Default);
catch (Exception e){}

//Getting the object against a given key
    obj = _cache.get(key);
catch (Exception e){}

Figure 3: Distributed cache being used in JSP Servlets application for data storage

At a conceptual level, the following illustration shows how you can use a distributed caching infrastructure with any Java application server such as Apache/Tomcat, JBoss, WebLogic or WebSphere:

Figure 3: Distributed cache being used in JSP Servlets application for data storage

Distributed Cache - Scaling JSP Servlet Performance

Unlike a database server, a distributed cache can scale out into multiple cache servers clustered together thus boosting the overall performance and reliability. It can scale by using such schemes as partitioning and replicating of data among multiple inexpensive cache locations. It can add further reliability by reliable fail-safe mechanisms, such as replicating each partition to at least one other server in the cache cluster. This way, even if one cache location goes down, there is no loss of data.

How Does NCache Help?

NCache is a feature-rich distributed cache that boosts JSP Servlets performance. Following are simple steps to quickly start using it in your application on any leading application server such as Apache/Tomcat, JBoss, WebLogic or WebSphere:

  • Install NCache: On your Java web server and two cache servers
  • Create a cache: Through a GUI based NCache Manager tool
  • Cache application data in NCache: If you want to use NCache for object caching in your JSP application, you will need to make NCache API calls to store and fetch your Java objects from the cache.
  • Reference "NCClient.jar" and "NCActivate.jar" files in your project.
  • Include "javaReg.Properties" file into the CLASSPATH of your project.
  • Use import com.alachisoft.ncache.web.caching.*; in your project
  • Monitor NCache performance: NCache performance can be monitored through a rich set of PerfMon counters.