jakarta-jcs-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Rasmussen <rasmus...@2e-systems.com>
Subject JCS Performance test
Date Tue, 05 Jul 2005 08:47:25 GMT
Hi,

like saipradeep I'm new to JCS.

I've read the document on JCS written 
by Aaron Asmuts. 
Trying to play with the example application
from that document (the book store example),
I've adopted the code to fit into the needs
of the project I'm currently working on.

To test the performance of the application,
basically I collect some data from the database,
knowing that the cache is empty at this point.

Immediately after that, I query all the objects using exactly
the same keys as the database query, and sure enough
the application finds them all in the cache.
The Ant log file shows that during the first operation
there are only "misses" and during the second
obviously only hits.

Now, when timing these two actions (getting all
the information from the db and after that reading
it all from the cache) the cache access is only
faster if I create a small number of objects (some 250). 
By that point the cache access continues to grow slower
than the direct database access.

Raising the available amount of memory, like this:

java -Xms128M -Xmx256M myClass


didn't affect this unsatisfying behavior in any way. Initially
I tried to create about 8600 objects (small objects
having only 5 fields containing information about
airports) which I subsequently accessed directly from 
the cache. Constructing the objects was no problem, but
reading from the cache was extremely slow and after some 
20 min, I broke off this action, having "read" only about 2000
objects ! (my workstation is a dell 1.8 Ghz computer with 512 MB RAM)


My cache.ccf file looks like this:

# DEFAULT CACHE REGION

jcs.default=DC
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
JCS.default.cacheattributes.MaxObjects=10000
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=false
jcs.default.cacheattributes.maxMemoryIdleTimeSeconds=3600
jcs.default.elementattributes.maxLifeSeconds=3600
jcs.default.elementattributes.IdleTime=1800
jcs.default.elementattributes.IsSpool=true
jcs.default.elementattributes.IsLateral=false
jcs.default.elementattributes.IsRemote=false



# PREDEFINED CACHE REGIONSInicially

jcs.region.testCache1=DC
jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.testCache1.cacheattributes.MaxObjects=10000
jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.testCache1.cacheattributes.maxMemoryIdleTimeSeconds=7200
jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.testCache1.elementattributes.IdleTime=1800
jcs.region.testCache1.elementattributes.IsEternal=false
jcs.region.testCache1.elementattributes.IsSpool=true
jcs.region.testCache1.elementattributes.IsLateral=false
jcs.region.testCache1.elementattributes.IsRemote=false



#### AVAILABLE AUXILIARY CACHES

jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
jcs.auxiliary.DC.attributes.DiskPath=/tmp/jcs/raf
jcs.auxiliary.DC.attributes.MaxPurgatorySize=10000
jcs.auxiliary.DC.attributes.MaxKeySize=10000
jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000
jcs.auxiliary.DC.attributes.MaxRecycleBinSize=7500



The main class is, though adapted, pretty much kept as the example
code by Aaron Asmuts (I apologize for the 
bad format of the code that might be caused by my email client):


public class AirportObjManager {
	
	private static AirportObjManager instance;
	private static int checkedOut = 0;
	private static JCS airportCache;
	private DatabaseManager db;
		
	
	private AirportObjManager() {
		
		try {			
			airportCache = JCS.getInstance("testCache1");
		}		
		catch (Exception e) {
			System.out.println("Error trying to initialize
			the cache region.");
			e.printStackTrace();
		}
	}
	
	
	/* Accesspoint */	
	public static AirportObjManager getInstance() {
				
		synchronized (AirportObjManager.class) {
			if (instance == null) {			
				instance = new AirportObjManager();
			}	
		}
		
		synchronized (instance) {
			checkedOut++;
		}
		
		return instance;
	}
	
	
/**
* @param airportCode
* @return AirportObj
*/
public AirportObj getAirportObj(String airportCode) {
	
	return getAirportObj(airportCode, true);	
}
	

/**
 * @param airportCode
 * @param fromCache
 * @return AirportObj
 */
public AirportObj getAirportObj(String airportCode, boolean fromCache) {
	
	AirportObj airObj = null;
		
	if (fromCache) {
           airObj = (AirportObj) airportCache.get(airportCode);
	}
		
	if (airObj == null) {
		//System.out.println("Says the getAirportObj Method:
		Object"
		+ airportCode + " not in cache, fetching from
		database.");

	airObj = (AirportObj) loadAirportObj (airportCode);
	}
		return airObj;
	}
	
	
	/** 
	 * loads the airport from the database 
	 *  and creates an object from it
	 *  
	 * @param aCode
	 * @return AirportObj
	 */
	public AirportObj loadAirportObj(String aCode) {
		
		AirportObj airport_object = new AirportObj();
		boolean found = false;
		
		// Here I fetch the data from the db and initialize
		// the fields of the object with the values
	        		}
        		}

	        
        
       		if (found) {
        		// put it into the cache
        		try {
        		airportCache.put
			(airport_object.getAirport_code(),
			airport_object);

			//System.out.println("Just put the airport object '" 
			// +airport_object.getAirport_code() + 
			//"' into the cache !");
        		}
        		catch (CacheException ce) {
        		ce.printStackTrace();
        		System.out.println("Error trying to put the
			newly created object into the cache.");
        		}
        	}
            	
    		return airport_object; 
	}


	/*
 	 * The method used for testing
 	 * the access of the cache.
 	 */
 	public void compareAccess() {
 		
 		AirportObj airportObj;
 		//String airport;
 		double timeBefore = 0;
 		double timeAfter = 0; 		
 		
 		ArrayList list = getDistinctCodes(); 		

	        //  Execute the getAirportObj method with all the
		//  entries in the list as arguments, 
 		//  create objects for all of them, and store them in
		//  the cache.
	        //  Time the operation.

	        timeBefore = System.currentTimeMillis();
	        for (int i=0; i<list.size();i++) {
	              airportObj = getAirportObj((String) list.get(i));
	              //System.out.println(airport);
	        }
	        timeAfter = System.currentTimeMillis();
	        
	        System.out.println("First operation (reading from DB)
		took " + ((timeAfter-timeBefore)/1000) +
       		" seconds (" + list.size() + " objects).");
	        
	        
	  
	        	        
	        // Now do the same again ( all objects from  previous
		// operation should now be in the cache)

	        timeBefore = System.currentTimeMillis();
	        for (int i=0; i<list.size();i++) {
        	     airportObj = getAirportObj(  (String) list.get(i));
	             //System.out.println(airport);
	        }
	        timeAfter = System.currentTimeMillis();
	        
	        System.out.println("Second operation (reading from
		cache) took " + ((timeAfter-timeBefore)/1000)
	        + " seconds (" + list.size() + " objects).");
	        
	}

}

Is there anything anyone can think of that I might have
forgotten or that I've done wrong, which could have caused
the bad performance results ?

I'd be happy for any hint or comment.

Regards
Thomas


---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Mime
View raw message