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 vinay b <vy...@gmail.com> on 2008/07/18 20:06:55 UTC
what happened to my cache keys
I seem to be losing about 90 % of my keys:
1. insert 500,000 elements in the cache via a loop
2. loop through and check whether all elements are accesable
The results and code snippets follow:
STATS:
The stats I get (verified both via a counter I implement) and via the
stats() method are
Thanks in advance
Vin B
from my code debugs:
found 45963 in 490001 tries
end get, ... found 55962 in 500001 tries
from the stats:
Region Name = testCache1
HitCountRam = 0
HitCountAux = 55962
---------------------------LRU Memory Cache
List Size = 9998
Map Size = 9998
Put Count = 555962 ==================================> ????
Hit Count = 0
Miss Count = 500000 =================================> why am I missing hits
here
---------------------------Indexed Disk Cache
Is Alive = true
Key Map Size = 55962 ================================> ????
Data File Length = 38544627
Hit Count = 55962
Bytes Free = 0
Optimize Operation Count = 0
Times Optimized = 0
Recycle Count = 0
Recycle Bin Size = 0
Startup Size = 46431
Purgatory Hits = 0
Purgatory Size = 0
Working = true
Alive = true
Empty = true
Size = 0
Jul 18, 2008 12:28:00 PM
org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache$ShutdownHook run
WARNING: Region [testCache1] Disk cache not shutdown properly, shutting down
now.
CODE
# DEFAULT CACHE REGION
#jcs.default=DC,LTCP
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
# PRE-DEFINED CACHE REGIONS
#jcs.region.testCache1=DC,LTCP
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.UseMemoryShrinker=true
jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=600
jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=500
jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.testCache1.elementattributes.IsEternal=true
# 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=c:/tmp
jcs.auxiliary.DC.attributes.maxKeySize=1000000
///////////////////////////////////////////
package com.interlegis.ehcachevsjcs;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jcs.JCS;
import org.apache.jcs.access.exception.CacheException;
import org.apache.jcs.engine.CompositeCacheAttributes;
import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
import org.apache.jcs.utils.struct.LRUMap;
public class JCSApp {
private static int MAX_NUM = 500000;
private Log log = null;
private JCS jcs = null;
public void init() throws CacheException {
log = LogFactory.getLog(LRUMap.class);
jcs = JCS.getInstance("testCache1");
}
public void insert(int key) throws CacheException {
jcs.put(Integer.toString(key), new MyObjectVO(Integer.toString(key),
"some string" + Integer.toString(key)));
}
public void insertMany(int maxNum) throws CacheException {
for (int i = 0; i < maxNum; i++) {
insert(i);
if ((i % 10000) == 0) {
System.out.println("inserted " + i + " records");
}
}
}
public Object get(int key) {
return jcs.get(Integer.toString(key));
}
public void getMany(int maxNum) {
int count = 0;
int i = 0;
for (i = 0; i < maxNum; i++) {
if (get(i) != null) {
count++;
}
if ((i % 10000) == 0) {
System.out.println("found " + count + " in " + (i + 1)
+ " tries");
}
}
System.out.println("end get, ... found " + count + " in " + (i + 1)
+ " tries");
}
public void junk() {
}
public void printStats() {
;
System.out.println(jcs.getStats());
}
public static void main(String[] args) {
JCSApp jc = new JCSApp();
try {
jc.init();
jc.insertMany(MAX_NUM);
System.out.println("insert complete");
jc.getMany(MAX_NUM);
jc.printStats();
} catch (CacheException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Re: what happened to my cache keys
Posted by vinay b <vy...@gmail.com>.
Yes, that's my intent. Basically, I'd like to have this cache persist all
elements on disk file when shut down.
THanks
On Fri, Jul 18, 2008 at 3:10 PM, Tim Cronin <tc...@interwoven.com> wrote:
> jcs.auxiliary.DC.attributes.maxKeySize=1000000
>
> it should spool to disk for overflow?
>
> -----Original Message-----
> From: Niall Gallagher [mailto:niall@switchfire.com]
> Sent: Friday, July 18, 2008 1:18 PM
> To: JCS Users List
> Subject: Re: what happened to my cache keys
>
> MaxObjects=10000 ?
>
> On Fri, 2008-07-18 at 13:06 -0500, vinay b wrote:
>
> > I seem to be losing about 90 % of my keys:
> >
> > 1. insert 500,000 elements in the cache via a loop
> > 2. loop through and check whether all elements are accesable
> >
> > The results and code snippets follow:
> >
> > STATS:
> >
> > The stats I get (verified both via a counter I implement) and via the
> > stats() method are
> >
> > Thanks in advance
> >
> > Vin B
> >
> > from my code debugs:
> > found 45963 in 490001 tries
> > end get, ... found 55962 in 500001 tries
> >
> >
> > from the stats:
> > Region Name = testCache1
> > HitCountRam = 0
> > HitCountAux = 55962
> >
> > ---------------------------LRU Memory Cache
> > List Size = 9998
> > Map Size = 9998
> > Put Count = 555962 ==================================> ????
> > Hit Count = 0
> > Miss Count = 500000 =================================> why am I
> missing hits
> > here
> > ---------------------------Indexed Disk Cache
> > Is Alive = true
> > Key Map Size = 55962 ================================> ????
> > Data File Length = 38544627
> > Hit Count = 55962
> > Bytes Free = 0
> > Optimize Operation Count = 0
> > Times Optimized = 0
> > Recycle Count = 0
> > Recycle Bin Size = 0
> > Startup Size = 46431
> > Purgatory Hits = 0
> > Purgatory Size = 0
> > Working = true
> > Alive = true
> > Empty = true
> > Size = 0
> > Jul 18, 2008 12:28:00 PM
> > org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache$ShutdownHook
> run
> > WARNING: Region [testCache1] Disk cache not shutdown properly,
> shutting down
> > now.
> >
> >
> > CODE
> > # DEFAULT CACHE REGION
> >
> > #jcs.default=DC,LTCP
> > jcs.default=DC
> >
> jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttribut
> es
> > jcs.default.cacheattributes.MaxObjects=10000
> >
> jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory
> .lru.LRUMemoryCache
> >
> > # PRE-DEFINED CACHE REGIONS
> >
> > #jcs.region.testCache1=DC,LTCP
> > jcs.region.testCache1=DC
> >
> jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCac
> heAttributes
> > jcs.region.testCache1.cacheattributes.MaxObjects=10000
> >
> jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.jcs.eng
> ine.memory.lru.LRUMemoryCache
> > jcs.region.testCache1.cacheattributes.UseMemoryShrinker=true
> > jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=3600
> > jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=600
> > jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=500
> >
> jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAtt
> ributes
> > jcs.region.testCache1.elementattributes.IsEternal=true
> >
> >
> > # AVAILABLE AUXILIARY CACHES
> >
> 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=c:/tmp
> > jcs.auxiliary.DC.attributes.maxKeySize=1000000
> >
> >
> >
> > ///////////////////////////////////////////
> > package com.interlegis.ehcachevsjcs;
> >
> > import org.apache.commons.logging.Log;
> > import org.apache.commons.logging.LogFactory;
> > import org.apache.jcs.JCS;
> > import org.apache.jcs.access.exception.CacheException;
> > import org.apache.jcs.engine.CompositeCacheAttributes;
> > import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
> > import org.apache.jcs.utils.struct.LRUMap;
> >
> > public class JCSApp {
> >
> > private static int MAX_NUM = 500000;
> >
> > private Log log = null;
> > private JCS jcs = null;
> >
> > public void init() throws CacheException {
> > log = LogFactory.getLog(LRUMap.class);
> > jcs = JCS.getInstance("testCache1");
> > }
> >
> > public void insert(int key) throws CacheException {
> > jcs.put(Integer.toString(key), new
> MyObjectVO(Integer.toString(key),
> > "some string" + Integer.toString(key)));
> > }
> >
> > public void insertMany(int maxNum) throws CacheException {
> > for (int i = 0; i < maxNum; i++) {
> > insert(i);
> >
> > if ((i % 10000) == 0) {
> > System.out.println("inserted " + i + " records");
> > }
> > }
> > }
> >
> > public Object get(int key) {
> > return jcs.get(Integer.toString(key));
> > }
> >
> > public void getMany(int maxNum) {
> > int count = 0;
> > int i = 0;
> > for (i = 0; i < maxNum; i++) {
> > if (get(i) != null) {
> > count++;
> > }
> >
> > if ((i % 10000) == 0) {
> > System.out.println("found " + count + " in " + (i + 1)
> > + " tries");
> > }
> > }
> >
> > System.out.println("end get, ... found " + count + " in " + (i
> + 1)
> > + " tries");
> > }
> >
> > public void junk() {
> >
> > }
> >
> > public void printStats() {
> > ;
> > System.out.println(jcs.getStats());
> > }
> >
> > public static void main(String[] args) {
> > JCSApp jc = new JCSApp();
> >
> > try {
> > jc.init();
> > jc.insertMany(MAX_NUM);
> > System.out.println("insert complete");
> > jc.getMany(MAX_NUM);
> > jc.printStats();
> >
> > } catch (CacheException e) {
> > // TODO Auto-generated catch block
> > e.printStackTrace();
> > }
> >
> > }
> > }
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
>
>
RE: what happened to my cache keys
Posted by Tim Cronin <tc...@interwoven.com>.
jcs.auxiliary.DC.attributes.maxKeySize=1000000
it should spool to disk for overflow?
-----Original Message-----
From: Niall Gallagher [mailto:niall@switchfire.com]
Sent: Friday, July 18, 2008 1:18 PM
To: JCS Users List
Subject: Re: what happened to my cache keys
MaxObjects=10000 ?
On Fri, 2008-07-18 at 13:06 -0500, vinay b wrote:
> I seem to be losing about 90 % of my keys:
>
> 1. insert 500,000 elements in the cache via a loop
> 2. loop through and check whether all elements are accesable
>
> The results and code snippets follow:
>
> STATS:
>
> The stats I get (verified both via a counter I implement) and via the
> stats() method are
>
> Thanks in advance
>
> Vin B
>
> from my code debugs:
> found 45963 in 490001 tries
> end get, ... found 55962 in 500001 tries
>
>
> from the stats:
> Region Name = testCache1
> HitCountRam = 0
> HitCountAux = 55962
>
> ---------------------------LRU Memory Cache
> List Size = 9998
> Map Size = 9998
> Put Count = 555962 ==================================> ????
> Hit Count = 0
> Miss Count = 500000 =================================> why am I
missing hits
> here
> ---------------------------Indexed Disk Cache
> Is Alive = true
> Key Map Size = 55962 ================================> ????
> Data File Length = 38544627
> Hit Count = 55962
> Bytes Free = 0
> Optimize Operation Count = 0
> Times Optimized = 0
> Recycle Count = 0
> Recycle Bin Size = 0
> Startup Size = 46431
> Purgatory Hits = 0
> Purgatory Size = 0
> Working = true
> Alive = true
> Empty = true
> Size = 0
> Jul 18, 2008 12:28:00 PM
> org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache$ShutdownHook
run
> WARNING: Region [testCache1] Disk cache not shutdown properly,
shutting down
> now.
>
>
> CODE
> # DEFAULT CACHE REGION
>
> #jcs.default=DC,LTCP
> jcs.default=DC
>
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttribut
es
> jcs.default.cacheattributes.MaxObjects=10000
>
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory
.lru.LRUMemoryCache
>
> # PRE-DEFINED CACHE REGIONS
>
> #jcs.region.testCache1=DC,LTCP
> jcs.region.testCache1=DC
>
jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCac
heAttributes
> jcs.region.testCache1.cacheattributes.MaxObjects=10000
>
jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.jcs.eng
ine.memory.lru.LRUMemoryCache
> jcs.region.testCache1.cacheattributes.UseMemoryShrinker=true
> jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=3600
> jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=600
> jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=500
>
jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAtt
ributes
> jcs.region.testCache1.elementattributes.IsEternal=true
>
>
> # AVAILABLE AUXILIARY CACHES
>
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=c:/tmp
> jcs.auxiliary.DC.attributes.maxKeySize=1000000
>
>
>
> ///////////////////////////////////////////
> package com.interlegis.ehcachevsjcs;
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.apache.jcs.JCS;
> import org.apache.jcs.access.exception.CacheException;
> import org.apache.jcs.engine.CompositeCacheAttributes;
> import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
> import org.apache.jcs.utils.struct.LRUMap;
>
> public class JCSApp {
>
> private static int MAX_NUM = 500000;
>
> private Log log = null;
> private JCS jcs = null;
>
> public void init() throws CacheException {
> log = LogFactory.getLog(LRUMap.class);
> jcs = JCS.getInstance("testCache1");
> }
>
> public void insert(int key) throws CacheException {
> jcs.put(Integer.toString(key), new
MyObjectVO(Integer.toString(key),
> "some string" + Integer.toString(key)));
> }
>
> public void insertMany(int maxNum) throws CacheException {
> for (int i = 0; i < maxNum; i++) {
> insert(i);
>
> if ((i % 10000) == 0) {
> System.out.println("inserted " + i + " records");
> }
> }
> }
>
> public Object get(int key) {
> return jcs.get(Integer.toString(key));
> }
>
> public void getMany(int maxNum) {
> int count = 0;
> int i = 0;
> for (i = 0; i < maxNum; i++) {
> if (get(i) != null) {
> count++;
> }
>
> if ((i % 10000) == 0) {
> System.out.println("found " + count + " in " + (i + 1)
> + " tries");
> }
> }
>
> System.out.println("end get, ... found " + count + " in " + (i
+ 1)
> + " tries");
> }
>
> public void junk() {
>
> }
>
> public void printStats() {
> ;
> System.out.println(jcs.getStats());
> }
>
> public static void main(String[] args) {
> JCSApp jc = new JCSApp();
>
> try {
> jc.init();
> jc.insertMany(MAX_NUM);
> System.out.println("insert complete");
> jc.getMany(MAX_NUM);
> jc.printStats();
>
> } catch (CacheException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> }
> }
---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org
Re: what happened to my cache keys
Posted by vinay b <vy...@gmail.com>.
Thanks, ... but if I take MaxObjects upto , say , 500,000 , I end up out of
heap space.
I was hoping that JCS would flush to disk fast enough that I wouldn't run
out of heap space.
I put in a Thread.sleep(10 seconds) every 10,000 inserts to try and slow
things down, but the same occurs. I was hoping that the cheanup
I tried reducing the shrinker interval too
Let me know if I've goofed up by not configuring the in-memory cache and
disk cache correctly
continuing, after waking up
inserted 180000 records
continuing, after waking up
inserted 190000 records
Jul 18, 2008 2:31:42 PM org.apache.jcs.engine.CacheEventQueue put
INFO: Cache event queue created: CacheEventQueue [listenerId=933524979,
cacheName=testCache1]
continuing, after waking up
inserted 200000 records
Jul 18, 2008 2:31:52 PM org.apache.jcs.engine.CacheEventQueue put
INFO: Cache event queue created: CacheEventQueue [listenerId=933524979,
cacheName=testCache1]
continuing, after waking up
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
Jul 18, 2008 2:31:56 PM
org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache$ShutdownHook run
WARNING: Region [testCache1] Disk cache not shutdown properly, shutting down
now.
Exception in thread "IndexedDiskCache-DisposalThread"
java.lang.OutOfMemoryError: Java heap space
jcs.default=DC
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=600000
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
# PRE-DEFINED CACHE REGIONS
jcs.region.testCache1=DC
jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.testCache1.cacheattributes.MaxObjects=600000
jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.testCache1.cacheattributes.UseMemoryShrinker=true
jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=30
jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=10
jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=500
jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.testCache1.elementattributes.IsEternal=true
# 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=c:/tmp
jcs.auxiliary.DC.attributes.maxKeySize=600000
//////////////////////////////////////////////////////////////////
On Fri, Jul 18, 2008 at 1:18 PM, Niall Gallagher <ni...@switchfire.com>
wrote:
> MaxObjects=10000 ?
>
> On Fri, 2008-07-18 at 13:06 -0500, vinay b wrote:
>
> > I seem to be losing about 90 % of my keys:
> >
> > 1. insert 500,000 elements in the cache via a loop
> > 2. loop through and check whether all elements are accesable
> >
>
Re: what happened to my cache keys
Posted by Niall Gallagher <ni...@switchfire.com>.
MaxObjects=10000 ?
On Fri, 2008-07-18 at 13:06 -0500, vinay b wrote:
> I seem to be losing about 90 % of my keys:
>
> 1. insert 500,000 elements in the cache via a loop
> 2. loop through and check whether all elements are accesable
>
> The results and code snippets follow:
>
> STATS:
>
> The stats I get (verified both via a counter I implement) and via the
> stats() method are
>
> Thanks in advance
>
> Vin B
>
> from my code debugs:
> found 45963 in 490001 tries
> end get, ... found 55962 in 500001 tries
>
>
> from the stats:
> Region Name = testCache1
> HitCountRam = 0
> HitCountAux = 55962
>
> ---------------------------LRU Memory Cache
> List Size = 9998
> Map Size = 9998
> Put Count = 555962 ==================================> ????
> Hit Count = 0
> Miss Count = 500000 =================================> why am I missing hits
> here
> ---------------------------Indexed Disk Cache
> Is Alive = true
> Key Map Size = 55962 ================================> ????
> Data File Length = 38544627
> Hit Count = 55962
> Bytes Free = 0
> Optimize Operation Count = 0
> Times Optimized = 0
> Recycle Count = 0
> Recycle Bin Size = 0
> Startup Size = 46431
> Purgatory Hits = 0
> Purgatory Size = 0
> Working = true
> Alive = true
> Empty = true
> Size = 0
> Jul 18, 2008 12:28:00 PM
> org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache$ShutdownHook run
> WARNING: Region [testCache1] Disk cache not shutdown properly, shutting down
> now.
>
>
> CODE
> # DEFAULT CACHE REGION
>
> #jcs.default=DC,LTCP
> 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
>
> # PRE-DEFINED CACHE REGIONS
>
> #jcs.region.testCache1=DC,LTCP
> 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.UseMemoryShrinker=true
> jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=3600
> jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=600
> jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=500
> jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAttributes
> jcs.region.testCache1.elementattributes.IsEternal=true
>
>
> # 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=c:/tmp
> jcs.auxiliary.DC.attributes.maxKeySize=1000000
>
>
>
> ///////////////////////////////////////////
> package com.interlegis.ehcachevsjcs;
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.apache.jcs.JCS;
> import org.apache.jcs.access.exception.CacheException;
> import org.apache.jcs.engine.CompositeCacheAttributes;
> import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
> import org.apache.jcs.utils.struct.LRUMap;
>
> public class JCSApp {
>
> private static int MAX_NUM = 500000;
>
> private Log log = null;
> private JCS jcs = null;
>
> public void init() throws CacheException {
> log = LogFactory.getLog(LRUMap.class);
> jcs = JCS.getInstance("testCache1");
> }
>
> public void insert(int key) throws CacheException {
> jcs.put(Integer.toString(key), new MyObjectVO(Integer.toString(key),
> "some string" + Integer.toString(key)));
> }
>
> public void insertMany(int maxNum) throws CacheException {
> for (int i = 0; i < maxNum; i++) {
> insert(i);
>
> if ((i % 10000) == 0) {
> System.out.println("inserted " + i + " records");
> }
> }
> }
>
> public Object get(int key) {
> return jcs.get(Integer.toString(key));
> }
>
> public void getMany(int maxNum) {
> int count = 0;
> int i = 0;
> for (i = 0; i < maxNum; i++) {
> if (get(i) != null) {
> count++;
> }
>
> if ((i % 10000) == 0) {
> System.out.println("found " + count + " in " + (i + 1)
> + " tries");
> }
> }
>
> System.out.println("end get, ... found " + count + " in " + (i + 1)
> + " tries");
> }
>
> public void junk() {
>
> }
>
> public void printStats() {
> ;
> System.out.println(jcs.getStats());
> }
>
> public static void main(String[] args) {
> JCSApp jc = new JCSApp();
>
> try {
> jc.init();
> jc.insertMany(MAX_NUM);
> System.out.println("insert complete");
> jc.getMany(MAX_NUM);
> jc.printStats();
>
> } catch (CacheException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> }
> }
Re: what happened to my cache keys
Posted by vinay b <vy...@gmail.com>.
Well, later on Friday, I fixed the cache keys not being inserted using the
following config (mainly settling the MaxObjects = -1 ) . I still have a few
issues but let me start by explaining what I'm attempting to achieve.
1. Create a persistant object store on DISK that can be created once and
deployed on various machines, .. a database, essentially . The intent is to
provide a data mapping that can be readily be used by multiple applications
and has good read performance speed. That is why I'm trying to get
everything on disk.
2. During application usage, we expect to maintain a reasonable balance
between in-memory entries and in-disk entries.
3. we expect a fairly large number of entries (about 500,000 objects)
Now for my issues.
1. How does one force everything to disk gracefully. I tried using the
dispose method at the end of my insertion routing (see program) and it works
okay for smaller sizes but when we get to larger entries, ..it sometimes
fails to write and / or sets the index key file to size 0, ..corrupting the
entire disk cache.
2. How can I get these many entries to disk. Smaller numbers are fine but
once I get above 300K - 400K, I can sometimes get "out of memory .. heap
exceptions" . I can tune this out to an extent by introducing a periodic
sleep() (currently 10 seconds every 10000 inserts), or possibly increasing
the heap size, but wanted to know if there were better methods.
Thanks,
Vin
2. I can now
# DEFAULT CACHE REGION
#jcs.default=DC,LTCP
jcs.default=DC
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=-1
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
# PRE-DEFINED CACHE REGIONS
jcs.region.testCache1=DC
jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.testCache1.cacheattributes.MaxObjects=-1
jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.testCache1.cacheattributes.UseMemoryShrinker=true
jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=5
jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=500
jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.testCache1.elementattributes.IsEternal=true
jcs.region.testCache1.atttributes.maxKeySize=1000000
# 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=c:/tmp
jcs.auxiliary.DC.attributes.maxKeySize=1000000
jcs.auxiliary.DC.attributes.MaxPurgatorySize=-1