How to Scale Java Applications with In-Memory Data Grid?

Java is very popular for developing high traffic enterprise level applications. These may be web applications developed in JSP, web services, or other server type applications. A wide range of these applications belong to Online Transaction Processing (OLTP) category involving millions of transactions.

You can handle this high transaction load by adding more web/app servers at the application tier but you cannot do the same at the database tier. The most you can do is buy more expensive hardware for your database server but that only takes you so far. Therefore, database always becomes a bottleneck and slows down your Java applications and may even grind it to halt if too much load is put on it.

Database being the bottleneck for web server farms

Database Scalability Problem in High Traffic Applications

Figure 1: Database Scalability Problem in High Traffic Applications

So, what to do about this? Well, in-memory data grid is becoming more popular for handling such situations. It lets you store application data in memory and reduce those expensive database trips that are overwhelming your database server. And, unlike a database, an in-memory data grid can scale by letting you add more servers at runtime as you increase your transaction load. This ensures that the in-memory data grid never becomes a scalability bottleneck.

An in-memory data grid also lets you persist you JSP Servlet sessions in it. These sessions are then replicated in a multi-server environment so you don’t lose any session data if a server ever goes down. And, an in-memory data grid is a much faster and more scalable session persistence store than your JSP Servlet container.

TayzGrid is an in-memory data grid for Java applications. It lets you store application data and also persist your JSP Servlet sessions in it. TayzGrid is extremely fast and scalable and provides linear scalability to you. Linear scalability means that as you add more grid servers in TayzGrid, your transaction capacity increases in a linear fashion.

Below is an example of using TayzGrid from Java Application:


 import com.alachisoft.TayzGrid.web.caching.Cache;
 import com.alachisoft. TayzGrid.runtime.*;
 ...
 public class MyCachingSample {
     private String url = "dbc:msql://20.200.20.1:1114/MyDatabase";
     public Employee GetEmployee(String empId) throws Exception
     {
          Employee emp = null;
          try {
               Cache cache = TayzGrid.initializeCache("MyDistributedCache");
                 emp = (Employee) cache.get(empId);
                 //If key not found in cache, Load from the database
                 if(emp == null)  {
                     ...
                         ResultSet rs = stmt.executeQuery("SELECT * FROM Employee WHERE EmpId ='"+ empId + "'");
                         if (rs.next()) {
                               emp = new Employee();
                               emp.EmpId = rs.getString("EmpId");
                               ...
                               //Cache key for future use
                               cache.insert(empId, emp, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Default);
                         }
                 }
          }
          catch (Exception exp) {
            throw exp;
          }
          //return the required object
          return emp;
 }
 

TayzGrid provides a powerful API for the developers to use it as their in-memory data grid and powerful GUI based and command-line administration and monitoring tools for IT folks. This makes TayzGrid management very simple.
Please download a fully working copy of TayzGrid Enterprise and try it out for yourself.

Tweet

About Iqbal Khan

Iqbal Khan is a Technology Evangelist at Alachisoft (http://www.alachisoft.com). Iqbal received his MS in Computer Science from Indiana University, Bloomington, in 1990. You can reach him at iqbal@alachisoft.com.
This entry was posted in In-Memory Data Grid, Scaling Java Applications and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


× 2 = four

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>