Skip to content
Snippets Groups Projects
Commit bf0304cd authored by srosse's avatar srosse
Browse files

OO-1128: reduce the size of the query plan cache if max memory is constraints

parent c7776a53
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,11 @@
*/
package org.olat.core.commons.persistence;
import static org.hibernate.cfg.AvailableSettings.QUERY_PLAN_CACHE_MAX_SIZE;
import static org.hibernate.cfg.AvailableSettings.QUERY_PLAN_CACHE_PARAMETER_METADATA_MAX_SIZE;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
......@@ -38,26 +43,15 @@ import java.util.Properties;
*/
public class DBVendorHibernatePropertiesSimplification extends Properties {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
public DBVendorHibernatePropertiesSimplification() {
super();
}
private static final long serialVersionUID = 2191563335029326588L;
/**
* First added key valu pairs, which are eventually overwritten by values added during a {@link #setMoreProperties(Map)} call.
* First added key value pairs, which are eventually overwritten by values added during a {@link #setMoreProperties(Map)} call.
* @param firstKeyValues
*/
public DBVendorHibernatePropertiesSimplification(Properties firstKeyValues) {
super();
optimizeForEnvironment(firstKeyValues);
putAll(firstKeyValues);
}
......@@ -65,8 +59,50 @@ public class DBVendorHibernatePropertiesSimplification extends Properties {
* add more key value pairs
* @param more
*/
public void setAddMoreProperties(Map<String,String> more){
public void setAddMoreProperties(Properties more) {
optimizeForEnvironment(more);
putAll(more);
}
private void optimizeForEnvironment(Properties more) {
List<Object> keys = new ArrayList<>(more.keySet());
for(Object key:keys) {
optimizeForEnvironment(key, more);
}
}
private void optimizeForEnvironment(Object key, Properties properties) {
if(QUERY_PLAN_CACHE_MAX_SIZE.equals(key)) {
MemorySize mem = getMaxMemoryAvailable();
if(mem == MemorySize.small) {
properties.put(QUERY_PLAN_CACHE_MAX_SIZE, "512");
} else if(mem == MemorySize.medium) {
properties.put(QUERY_PLAN_CACHE_MAX_SIZE, "1024");
}
} else if(QUERY_PLAN_CACHE_PARAMETER_METADATA_MAX_SIZE.equals(key)) {
MemorySize mem = getMaxMemoryAvailable();
if(mem == MemorySize.small) {
properties.put(QUERY_PLAN_CACHE_PARAMETER_METADATA_MAX_SIZE, "32");
} else if(mem == MemorySize.medium) {
properties.put(QUERY_PLAN_CACHE_PARAMETER_METADATA_MAX_SIZE, "64");
}
}
}
private MemorySize getMaxMemoryAvailable() {
long maxMem = Runtime.getRuntime().maxMemory();
if(maxMem < 550000000l) {
return MemorySize.small;
} else if(maxMem < 1048000000l) {
return MemorySize.medium;
}
return MemorySize.large;
}
private enum MemorySize {
small,
medium,
large
}
}
......@@ -147,6 +147,9 @@
olat works only with level 2; the database must support level 2
-->
<prop key="hibernate.connection.isolation">2</prop>
<!-- The 2 options below are automatically reduced if not enough memory is available -->
<prop key="hibernate.query.plan_cache_max_size">2048</prop>
<prop key="hibernate.query.plan_parameter_metadata_max_size">128</prop>
<prop key="javax.persistence.lock.timeout">30000</prop>
</props>
</constructor-arg>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment