[jboss-user] [JBoss Cache: Core Edition] - Problem in persisting HashMap in cache
sridhar_ratna
do-not-reply at jboss.com
Fri Jun 5 12:25:11 EDT 2009
My requirement is that , i need to group couple of objects together and process them.
the group size may be small or may be some thousands.
On certain scenarios the objects may be removed from current group and placed in existing group or new group will get created.
As there is a lot of overhead for jboss cache in handling large key value pairs under a node, i designed my application in such a way that, I'll populate a HashMap of key value pairs and put in under cache node with dummy key "0". This way given me very high performance and persistence speed with JBDM as persistence store.
When i populate the entire HashMap t oncewith 1000 object and persisted in cache, the data file size is around 100K. and its perfect.
But when i repeated the population of cache in iteratively i mean gradually, with the same 1000 objects, the data file is grown to 30MB. how bad.
one step population code is
| public class TestCache {
| private Cache<Long, Object> cache = null;
|
| public TestCache(){
| try {
| CacheFactory<Long, Object> factory = new DefaultCacheFactory<Long, Object>();
| String cacheConfigFile = "cacheloader.xml";
| cache = factory.createCache(cacheConfigFile);
| cache.create();
| cache.start();
|
| } catch (ConfigurationException e) {
| } catch (CacheException e) {
| }
| }
|
| public void populateCache(){
|
| Map<Long, Object> empMap= new HashMap<Long, Object>();
| for(long i=1; i <= 1000; i++){
| Employee emp = new Employee(i,"Test name "+i,"test region "+i);
| empMap.put(i, emp);
| }
|
| Node<Long, Object> collNode = cache.getRoot().addChild(Fqn.fromElements("test","emp","cache"));
| collNode.put(0L, empMap);
| cache.stop();
|
| }
| public static void main(String[] args) {
| TestCache tc= new TestCache();
| tc.populateCache();
|
| }
| }
|
the second program which kept iteratively is
| public class TestCache {
| private Cache<Long, Object> cache = null;
|
| public TestCache(){
| try {
| CacheFactory<Long, Object> factory = new DefaultCacheFactory<Long, Object>();
| String cacheConfigFile = "cacheloader.xml";
| cache = factory.createCache(cacheConfigFile);
| cache.create();
| cache.start();
| } catch (ConfigurationException e) {
| } catch (CacheException e) {
| }
| }
|
| public void populateCache(){
| Map<Long, Object> empMap= null;
| for(long i=1; i <= 1000; i++){
| Employee emp = new Employee(i,"Test name "+i,"test region "+i);
| Node<Long, Object> collNode = cache.getRoot().getChild(Fqn.fromElements("test","emp","cache"));
|
| if(collNode == null){
| collNode = cache.getRoot().addChild(Fqn.fromElements("test","emp","cache"));
| }
|
| empMap = (Map<Long, Object>)collNode.get(0L);
| if(empMap == null)
| empMap= new HashMap<Long, Object>();
|
| empMap.put(i, emp);
| collNode.clearData();
| collNode.remove(0L);
| collNode.put(0L, empMap);
| }
|
| cache.stop();
| }
|
| public static void main(String[] args) {
| TestCache tc= new TestCache();
| tc.populateCache();
|
| }
|
| }
|
|
configuration file is
| <?xml version="1.0" encoding="UTF-8"?>
| <jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xmlns="urn:jboss:jbosscache-core:config:3.0">
|
| <transaction
| transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup" />
| <locking
| isolationLevel="REPEATABLE_READ"
| lockParentForChildInsertRemove="false"
| lockAcquisitionTimeout="20000"
| nodeLockingScheme="mvcc"
| writeSkewCheck="false"
| concurrencyLevel="500"/>
| <invocationBatching enabled="true"/>
| <jmxStatistics enabled="true"/>
| <loaders passivation="false" shared="false">
| <preload>
| <node fqn="/" />
| </preload>
| <loader class ="org.jboss.cache.loader.jdbm.JdbmCacheLoader"
| async="false" fetchPersistentState="true" ignoreModifications="false" >
| <properties>
| location=/home/sridhar/cache
| cache.jdbc.connection.factory=org.jboss.cache.loader.C3p0ConnectionFactory
| c3p0.maxPoolSize=10
| c3p0.checkoutTimeout=5000
| </properties>
| </loader>
| </loaders>
| </jbosscache>
|
|
in the second program when i replaced the HashMap with Set, there is no difference in the size of data files created.
Why such strange behaviour. what will be the solution to this?
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4235712#4235712
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4235712
More information about the jboss-user
mailing list