IDEMPIERE-3653 1008016 Reduce cache max size from 2000 to 1000. Add max-idle config for hazelcast map ( 30 minutes ).

This commit is contained in:
Heng Sin Low 2017-05-24 17:31:41 +08:00
parent f80cb9ca7a
commit 6105b42ecb
3 changed files with 49 additions and 4 deletions

View File

@ -68,7 +68,24 @@ public class CacheMgt
/** Logger */ /** Logger */
private static CLogger log = CLogger.getCLogger(CacheMgt.class); private static CLogger log = CLogger.getCLogger(CacheMgt.class);
private final static int MAX_SIZE = 2000; private static int MAX_SIZE = 1000;
static
{
try
{
String maxSize = System.getProperty("Cache.MaxSize");
if (maxSize != null && maxSize.trim().length() > 0)
{
int max = 0;
try
{
max = Integer.parseInt(maxSize.trim());
} catch (Throwable t) {}
if (max > 0)
MAX_SIZE = max;
}
} catch (Throwable t) {}
}
/************************************************************************** /**************************************************************************
* Create Cache Instance * Create Cache Instance

View File

@ -135,7 +135,7 @@
automatically evicted from the map. Entry is touched if get, put or containsKey is called. automatically evicted from the map. Entry is touched if get, put or containsKey is called.
Any integer between 0 and Integer.MAX_VALUE. 0 means infinite. Default is 0. Any integer between 0 and Integer.MAX_VALUE. 0 means infinite. Default is 0.
--> -->
<max-idle-seconds>0</max-idle-seconds> <max-idle-seconds>1800</max-idle-seconds>
<!-- <!--
Valid values are: Valid values are:
NONE (no eviction), NONE (no eviction),
@ -150,7 +150,7 @@
Any integer between 0 and Integer.MAX_VALUE. 0 means Any integer between 0 and Integer.MAX_VALUE. 0 means
Integer.MAX_VALUE. Default is 0. Integer.MAX_VALUE. Default is 0.
--> -->
<max-size policy="cluster_wide_map_size">2000</max-size> <max-size policy="cluster_wide_map_size">1000</max-size>
<!-- <!--
When max. size is reached, specified percentage of When max. size is reached, specified percentage of
the map will be evicted. Any integer between 0 and 100. the map will be evicted. Any integer between 0 and 100.

View File

@ -15,9 +15,11 @@ package org.idempiere.hazelcast.service;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Date; import java.util.Date;
import java.util.Enumeration;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
@ -30,6 +32,8 @@ import org.osgi.framework.BundleContext;
import com.hazelcast.config.Config; import com.hazelcast.config.Config;
import com.hazelcast.config.FileSystemXmlConfig; import com.hazelcast.config.FileSystemXmlConfig;
import com.hazelcast.config.MapConfig;
import com.hazelcast.config.UrlXmlConfig;
import com.hazelcast.core.*; import com.hazelcast.core.*;
/** /**
@ -123,12 +127,36 @@ public class Activator implements BundleActivator {
Config config = new FileSystemXmlConfig(file); Config config = new FileSystemXmlConfig(file);
config.setClassLoader(getClass().getClassLoader()); config.setClassLoader(getClass().getClassLoader());
hazelcastInstance = Hazelcast.newHazelcastInstance(config); hazelcastInstance = Hazelcast.newHazelcastInstance(config);
MapConfig mc = config.getMapConfig("default");
if (mc != null) {
System.out.println("Hazelcast Max Size Config: "+mc.getMaxSizeConfig().getMaxSizePolicy() + " " + mc.getMaxSizeConfig().getSize());
}
return; return;
} catch (FileNotFoundException e) {} } catch (FileNotFoundException e) {}
} }
Enumeration<URL> entries = getContext().getBundle().findEntries("/", "hazelcast.xml", false);
URL url = entries.hasMoreElements() ? entries.nextElement() : null;
if (url != null) {
try {
Config config = new UrlXmlConfig(url);
config.setClassLoader(getClass().getClassLoader());
hazelcastInstance = Hazelcast.newHazelcastInstance(config);
MapConfig mc = config.getMapConfig("default");
if (mc != null) {
System.out.println("Hazelcast Max Size Config: "+mc.getMaxSizeConfig().getMaxSizePolicy() + " " + mc.getMaxSizeConfig().getSize());
}
return;
} catch (IOException e) {}
}
Config config = new Config(); Config config = new Config();
config.setClassLoader(getClass().getClassLoader()); config.setClassLoader(getClass().getClassLoader());
hazelcastInstance = Hazelcast.newHazelcastInstance(config); hazelcastInstance = Hazelcast.newHazelcastInstance(config);
MapConfig mc = config.getMapConfig("default");
if (mc != null) {
System.out.println("Hazelcast Max Size Config: "+mc.getMaxSizeConfig().getMaxSizePolicy() + " " + mc.getMaxSizeConfig().getSize());
}
} }
}); });
} }