Alachisoft.com

Contact Us
Live Chat

Improve Java Servlet Performance with In-Memory Data Grid

Java Servlet has become a really popular choice for developing high-transaction web applications. The reasons are simple; Java Servlet is based on Java and is therefore platform independent. It helps maintain complex, information-rich, dynamic Java 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: Java Servlets Performance Bottlenecks

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

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

Database bottleneck in Java Servlet applications
Figure 1: Database bottleneck in Java Servlet applications

The Solution: In-Memory Data Grid

The main reason for the database becoming a bottleneck is that while you can add more and more servers to the Java Servlet application web 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 Java Servlet performance bottlenecks by using an in-memory data grid for storing the frequently used data.

Think of an in-memory data grid as an in-memory database that can scale linearly to multiple servers and therefore never has 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 an in-memory data grid to achieve a considerable performance boost.

<% 
<%@page import="com.alachisoft.jvcache.web.caching.*" %>
 
<% 
String cacheId = "mycache"; 
Cache _cache; 
 
//Initializing the cache object  
try{ 
_    cache = JvCache.initializeCache(cacheId); 
} 
Catch (Exception e){} 

//Adding key (cache item name) and val (object) into the cache  
try{ 
_cache.add(key, val, null, 
Cache.NoAbsoluteExpiration, 
Cache.NoSlidingExpiration,
CacheItemPriority.Default); 

} 
catch (Exception e){} 
 
//Getting the object against a given key  
try{ 
obj = _cache.get(key); 
} 
catch (Exception e){} 
%> 
Figure 2: Source listing of a sample Java Servlet using in-memory data grid

At a conceptual level, the following illustration shows how you can use an in-memory data grid infrastructure with any Java application server such as Apache/Tomcat, JBoss, WebLogic or WebSphere:

In-Memory data grid used in Java Servlet application
Figure 3: In-Memory data grid used in Java Servlet application

In-Memory Data Grid - Scaling Java Servlet Performance

Unlike a database server, an in-memory data grid 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 JvCache Help?

JvCache is a feature-rich in-memory data grid that boosts Java application and Java Servlet application performance and scalability. Here are some simple steps you could take to quickly benefit from it:

  • Install JvCache: on your Java web servers and two dedicated cache servers
  • Create a cache: through a GUI based JvCache Manager tool
  • Cache application data in JvCache: if you want to use JvCache for object caching in your Java Servlet application, you will need to make JvCache API calls to store and fetch your Java objects from the cache
  • Reference: All jar files should be referred from lib folder inside of installation folder
  • Include: javaReg.Properties file into the CLASSPATH of your project
  • Use: import com.alachisoft.jvcache.web.caching.*; in your project
  • Monitor JvCache performance: JvCache performance can be monitored through a rich set of JMX or PerfMon counters