How to Scale Java Applications with Distributed Cache?

Java is widely used for developing high traffic distributed applications. But, these high traffic Java applications are facing a major scalability problem. Although these applications can easily scale at application-tier level by adding more web servers to the web farm, their database cannot scale in the same manner to handle the growing number of transactions.

Figure shows the database scalability problem faced by high traffic applications.

Java DataBase Scalability

Java DataBase Scalability

Figure 1: Database Scalability Problem in High Traffic Applications

Databases can only process a certain number of requests per second. And, in high traffic applications where thousands or even tens of thousands of requests are reaching web-servers each second, database transactional limit easily exhausts and your Java application starts slowing down and can even grind to halt. And, the worst part is that this happens during your peak business hours and therefore causes greatest business loss due to a downtime.

So, what is a way to resolve this issue? Well, NCache as a Java distributed cache resolves your database scalability problem. It allows your applications to cache your application data and reduce those expensive database trips that are causing scalability bottleneck. And, NCache never becomes a scalability bottleneck because you can grow the cache cluster by adding more cache servers to it when you need to grow the transaction load. This is something you cannot do with your database server.

Download NCache free trial - Extremely fast and scalable in-memory distributed cache

NCache as a Java distributed cache also improves your application performance because all the cache data is kept in the memory instead of disk. And, as you know in-memory access is much faster than going to the database.

You can use NCache from any Java applications including JSP Servlets, Java web services and any other server type of Java applications with high transactional load. And, you can cache complex objects, JSP Sessions, Hibernate entities, Enterprise Java Beans, Spring objects and more.

Below is an example of using NCache as a distributed cache from a Java application:
import com.alachisoft.ncache.web.caching.Cache;
import com.alachisoft.ncache.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 = NCache.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;
    }
NCache provides an extensive set of features through its native Java cache API. And, you can use NCache from your Java applications running either on Windows or any flavor of Unix.

In summary, using NCache you can linearly scale your Java application and can boost application performance.

So, download a fully working 60-day trial of NCache Enterprise and try it out for yourself.

This entry was posted in Distributed Cache, Java and tagged , . Bookmark the permalink.

Leave a Reply

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


6 + five =

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>