You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-users@jakarta.apache.org by Jawahar Nayak <jl...@chambal.com> on 2009/05/01 13:02:18 UTC

Unable to get the stroed Cache

Hi,

I am using JCS for Disk Based Caching. I don't want to use memory cache. So
I set the configuration like this:

##############################################################
##### Default Region Configuration
jcs.default=DC
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=0
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
 
 
 
##############################################################
##### CACHE REGIONS
jcs.region.myRegion1=DC
jcs.region.myRegion1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.myRegion1.cacheattributes.MaxObjects=0
jcs.region.myRegion1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.myRegion1.cacheattributes.MaxSpoolPerRun=100
 
 
 
##############################################################
##### AUXILIARY CACHES
# Indexed Disk Cache
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=target/test-sandbox/indexed-disk-cache
jcs.auxiliary.DC.attributes.MaxPurgatorySize=1000
jcs.auxiliary.DC.attributes.MaxKeySize=1000
jcs.auxiliary.DC.attributes.MaxRecycleBinSize=5000
jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000
jcs.auxiliary.DC.attributes.OptimizeOnShutdown=true
jcs.auxiliary.DC.attributes.EventQueueType=POOLED
jcs.auxiliary.DC.attributes.EventQueuePoolName=disk_cache_event_queue
 
##############################################################
################## OPTIONAL THREAD POOL CONFIGURATION ########
 
# Disk Cache Event Queue Pool
thread_pool.disk_cache_event_queue.useBoundary=false
thread_pool.remote_cache_client.maximumPoolSize=15
thread_pool.disk_cache_event_queue.minimumPoolSize=1
thread_pool.disk_cache_event_queue.keepAliveTime=3500
thread_pool.disk_cache_event_queue.startUpSize=1

I set max object 0 so that all items are cache in disk.
jcs.default.cacheattributes.MaxObjects=0

As I set the maxkeysize=1000, after writing 1000 items, I am calling
jcs.freeMemoryElements(1000), so that all the items are successfully writen
to disk. But this method throwing exception: Update: Last item null.
jcs.auxiliary.DC.attributes.MaxKeySize=1000

I wrote 2000 items in cache, but I am able to get only 1000 items back.

What I am doing wrong ? I want to use this disk caching for items [
nearabout 50 lac items]
-- 
View this message in context: http://www.nabble.com/Unable-to-get-the-stroed-Cache-tp23331442p23331442.html
Sent from the JCS - Users mailing list archive at Nabble.com.


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


RE: Unable to get the stored Cache

Posted by Jawahar Nayak <jl...@chambal.com>.
 I also tried with MaxObject=10000, even then I got null while fetching
elements.
-- 
View this message in context: http://www.nabble.com/Unable-to-get-the-stored-Cache-tp23331442p23366759.html
Sent from the JCS - Users mailing list archive at Nabble.com.


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


RE: Unable to get the stored Cache

Posted by "Akture, Alper" <Al...@disney.com>.
I'm going to take a stab, and say maybe it's because MaxObjects=0 for
your region. I'm not sure, but maybe disk cache is only used for
overflow, and can't be used they way you're trying to? Just a guess
though.

Alper

-----Original Message-----
From: Sent: Friday, May 01, 2009 6:37 AM
To: jcs-users@jakarta.apache.org
Subject: Re: Unable to get the stored Cache


I am posting the running Example of the Application.

import java.io.IOException;
import java.util.Date;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.jcs.JCS;
import org.apache.jcs.access.exception.CacheException;

public class TestHashMemory {

    static JCS jcs = null;

    public void createHashTable(long hashsize) {
        try {
            jcs = JCS.getInstance("myregion");
            Hashtable objHash = new Hashtable();
            Date date = new Date();
            long start = date.getTime();//
            for (long i = 1; i <= hashsize; i++) {
                jcs.put("key" + i, i);
            }
            Date date1 = new Date();
            long end = date1.getTime();
            System.out.println("Time taken for creation : " + (end -
start));
            date = new Date();
            start = date.getTime();
            int missing = 0;
            for (long i = 1; i <= hashsize; i++) {
                Object obj = jcs.get("key" + i);
                if (obj == null) {
                    missing++;
                }
                System.out.println(obj);
            }
            System.out.println("Total Missing Objects: " + missing);
            date1 = new Date();
            end = date1.getTime();
            System.out.println("Time taken for read : " + (end -
start));
        } catch (Exception ex) {
            ex.printStackTrace();
        }


    }

    public static void main(String a[]) {
        try {
            TestHashMemory objTestHash = new TestHashMemory();
            objTestHash.createHashTable(2000);
            System.out.println("Press any key to exit");
            System.in.read();
        } catch (IOException ex) {
           
Logger.getLogger(TestHashMemory.class.getName()).log(Level.SEVERE, null,
ex);
        }
    }
}

############## - cache.ccf - ######################################
##############################################################
##### Default Region Configuration
jcs.default=DC
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttribut
es
jcs.default.cacheattributes.MaxObjects=0
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory
.lru.LRUMemoryCache



##############################################################
##### CACHE REGIONS
jcs.region.myRegion1=DC
jcs.region.myRegion1.cacheattributes=org.apache.jcs.engine.CompositeCach
eAttributes
jcs.region.myRegion1.cacheattributes.MaxObjects=0
jcs.region.myRegion1.cacheattributes.MemoryCacheName=org.apache.jcs.engi
ne.memory.lru.LRUMemoryCache
jcs.region.myRegion1.cacheattributes.MaxSpoolPerRun=1000



##############################################################
##### AUXILIARY CACHES
# Indexed Disk Cache
jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheF
actory
jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.Indexe
dDiskCacheAttributes
jcs.auxiliary.DC.attributes.DiskPath=target/test-sandbox/indexed-disk-ca
che
jcs.auxiliary.DC.attributes.MaxPurgatorySize=10000
jcs.auxiliary.DC.attributes.MaxKeySize=1000
jcs.auxiliary.DC.attributes.MaxRecycleBinSize=5000
jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000
jcs.auxiliary.DC.attributes.OptimizeOnShutdown=true
jcs.auxiliary.DC.attributes.EventQueueType=POOLED
jcs.auxiliary.DC.attributes.EventQueuePoolName=disk_cache_event_queue

##############################################################
################## OPTIONAL THREAD POOL CONFIGURATION ########

# Disk Cache Event Queue Pool
thread_pool.disk_cache_event_queue.useBoundary=false
thread_pool.remote_cache_client.maximumPoolSize=15
thread_pool.disk_cache_event_queue.minimumPoolSize=1
thread_pool.disk_cache_event_queue.keepAliveTime=3500
thread_pool.disk_cache_event_queue.startUpSize=1


##############################################################

I am using jcs-1.3.jar, and running the application of java6.

-- 
View this message in context:
http://www.nabble.com/Unable-to-get-the-stored-Cache-tp23331442p23333219
.html
Sent from the JCS - Users mailing list archive at Nabble.com.


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


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


Re: Unable to get the stored Cache

Posted by Jawahar Nayak <jl...@chambal.com>.
Thanks for the reply

If I am using MaxObjects=0, means No object stored in Memory. So It is not
useful to call feeMemoryElements(). PurgatoryArea is used before writing to
Disk. Can we flush all items in PurgatoryArea to  disk. 

Can anyone tell what configuration I should use to do the following:

Suppose I want to write maximum 5000 objects,

- I want to store all items in DiskCahe, no single object in Memory.
- I don't want to use MaxKeySize more than 1000

Thanks




-- 
View this message in context: http://www.nabble.com/Unable-to-get-the-stored-Cache-tp23331442p23404006.html
Sent from the JCS - Users mailing list archive at Nabble.com.


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


Re: Unable to get the stored Cache

Posted by Jan Swaelens <ja...@sofico.be>.
The error you are getting is 'normal' (if you have a look at the JCS code 
you'll see that an error is raised when no elements are in the memory 
cache when a 'freeMemoryElements' operation is executed) and can be 
avoided by implementing this principle:

                        CompositeCache cc = CompositeCacheManager.
getInstance().getCache("myRegion1");
                        int memorySize = cc.getMemoryCache().getSize();
                        System.out.println("Entries in memory cache: " + 
memorySize);
                        if(memorySize>0) {
                                int elementsToFree = 1000;
                                jcs
.freeMemoryElements(memorySize<elementsToFree?memorySize:elementsToFree);
                        }

By checking the size of the memory cache before calling the 'free' method, 
you only free if it's actually needed and only as much as possible.

This brings us to another issue with your scenario, if you use the 
MaxObjects=0 setting all data is written to the disk cache immediatly, 
nothing will be stored in the memory cache anyway.

I also noticed that you are using 'myregion' to access the cache region, 
but your config file defines 'myRegion1'. The result of this is that you 
get a cache region based on the settings defined in the config file for 
the default region (which means that you can make changes in the config 
file for  'myRegion1' as much as you want, it will have no effect).

Re: Unable to get the stored Cache

Posted by Jawahar Nayak <jl...@chambal.com>.
I am posting the running Example of the Application.

import java.io.IOException;
import java.util.Date;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.jcs.JCS;
import org.apache.jcs.access.exception.CacheException;

public class TestHashMemory {

    static JCS jcs = null;

    public void createHashTable(long hashsize) {
        try {
            jcs = JCS.getInstance("myregion");
            Hashtable objHash = new Hashtable();
            Date date = new Date();
            long start = date.getTime();//
            for (long i = 1; i <= hashsize; i++) {
                jcs.put("key" + i, i);
            }
            Date date1 = new Date();
            long end = date1.getTime();
            System.out.println("Time taken for creation : " + (end -
start));
            date = new Date();
            start = date.getTime();
            int missing = 0;
            for (long i = 1; i <= hashsize; i++) {
                Object obj = jcs.get("key" + i);
                if (obj == null) {
                    missing++;
                }
                System.out.println(obj);
            }
            System.out.println("Total Missing Objects: " + missing);
            date1 = new Date();
            end = date1.getTime();
            System.out.println("Time taken for read : " + (end - start));
        } catch (Exception ex) {
            ex.printStackTrace();
        }


    }

    public static void main(String a[]) {
        try {
            TestHashMemory objTestHash = new TestHashMemory();
            objTestHash.createHashTable(2000);
            System.out.println("Press any key to exit");
            System.in.read();
        } catch (IOException ex) {
           
Logger.getLogger(TestHashMemory.class.getName()).log(Level.SEVERE, null,
ex);
        }
    }
}

############## - cache.ccf - ######################################
##############################################################
##### Default Region Configuration
jcs.default=DC
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=0
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache



##############################################################
##### CACHE REGIONS
jcs.region.myRegion1=DC
jcs.region.myRegion1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.myRegion1.cacheattributes.MaxObjects=0
jcs.region.myRegion1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.myRegion1.cacheattributes.MaxSpoolPerRun=1000



##############################################################
##### AUXILIARY CACHES
# Indexed Disk Cache
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=target/test-sandbox/indexed-disk-cache
jcs.auxiliary.DC.attributes.MaxPurgatorySize=10000
jcs.auxiliary.DC.attributes.MaxKeySize=1000
jcs.auxiliary.DC.attributes.MaxRecycleBinSize=5000
jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000
jcs.auxiliary.DC.attributes.OptimizeOnShutdown=true
jcs.auxiliary.DC.attributes.EventQueueType=POOLED
jcs.auxiliary.DC.attributes.EventQueuePoolName=disk_cache_event_queue

##############################################################
################## OPTIONAL THREAD POOL CONFIGURATION ########

# Disk Cache Event Queue Pool
thread_pool.disk_cache_event_queue.useBoundary=false
thread_pool.remote_cache_client.maximumPoolSize=15
thread_pool.disk_cache_event_queue.minimumPoolSize=1
thread_pool.disk_cache_event_queue.keepAliveTime=3500
thread_pool.disk_cache_event_queue.startUpSize=1


##############################################################

I am using jcs-1.3.jar, and running the application of java6.

-- 
View this message in context: http://www.nabble.com/Unable-to-get-the-stored-Cache-tp23331442p23333219.html
Sent from the JCS - Users mailing list archive at Nabble.com.


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


Re: Unable to get the stored Cache

Posted by Jawahar Nayak <jl...@chambal.com>.
Thanks for the response.

OK, I set the MaxKeySize=10,000,000. It means I set store max 10,000,000
items. I set MaxPurgatorySize = 10000. I stored total 5,00,000 items. But
still I am getting 130191 items missing. If I set the maxpurgatorysize =
Maxkeysize, then get all the stored items. But this increase the memory
usages. Its taking 150 mb memory for 50,000 items

Is it possible to control the memory usage should not go more than 100 mb
for 10,000,000 items ?
-- 
View this message in context: http://www.nabble.com/Unable-to-get-the-stored-Cache-tp23331442p23420463.html
Sent from the JCS - Users mailing list archive at Nabble.com.


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