Make Idle Time configurable
This commit is contained in:
parent
04d361b80c
commit
591bca0c8d
2 changed files with 46 additions and 26 deletions
|
@ -65,6 +65,8 @@ public class ContentTripleSourceSDB extends ContentTripleSource {
|
|||
static final String PROPERTY_DB_TYPE = "VitroConnection.DataSource.dbtype";
|
||||
static final String PROPERTY_DB_MAX_ACTIVE = "VitroConnection.DataSource.pool.maxActive";
|
||||
static final String PROPERTY_DB_MAX_IDLE = "VitroConnection.DataSource.pool.maxIdle";
|
||||
static final String PROPERTY_DB_MAX_IDLE_TIME = "VitroConnection.DataSource.pool.maxIdleTime";
|
||||
static final String PROPERTY_DB_MAX_IDLE_TIME_EXCESS = "VitroConnection.DataSource.pool.maxIdleTimeExcess";
|
||||
static final String PROPERTY_DB_VALIDATION_QUERY = "VitroConnection.DataSource.validationQuery";
|
||||
static final String PROPERTY_DB_SDB_LAYOUT = "VitroConnection.DataSource.sdb.layout";
|
||||
|
||||
|
@ -77,6 +79,9 @@ public class ContentTripleSourceSDB extends ContentTripleSource {
|
|||
static final int MINIMUM_MAXACTIVE = 20; // ms
|
||||
static final int DEFAULT_MAXIDLE = 10; // ms
|
||||
|
||||
static final int DEFAULT_MAX_IDLE_TIME = 1800; // seconds
|
||||
static final int DEFAULT_MAX_IDLE_TIME_EXCESS = 300; // seconds
|
||||
|
||||
static final boolean DEFAULT_TESTONBORROW = true;
|
||||
static final boolean DEFAULT_TESTONRETURN = true;
|
||||
|
||||
|
|
|
@ -2,23 +2,6 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_DRIVER_CLASS;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_MAXACTIVE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_MAXIDLE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_TESTONBORROW;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_TESTONRETURN;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_TYPE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_VALIDATION_QUERY;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.MINIMUM_MAXACTIVE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_DRIVER_CLASS_NAME;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_MAX_ACTIVE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_MAX_IDLE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_PASSWORD;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_TYPE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_URL;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_USERNAME;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_VALIDATION_QUERY;
|
||||
|
||||
import java.beans.PropertyVetoException;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
@ -31,6 +14,27 @@ import com.mchange.v2.c3p0.ComboPooledDataSource;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_DRIVER_CLASS;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_MAXACTIVE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_MAXIDLE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_MAX_IDLE_TIME;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_MAX_IDLE_TIME_EXCESS;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_TESTONBORROW;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_TESTONRETURN;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_TYPE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_VALIDATION_QUERY;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.MINIMUM_MAXACTIVE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_DRIVER_CLASS_NAME;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_MAX_ACTIVE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_MAX_IDLE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_MAX_IDLE_TIME;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_MAX_IDLE_TIME_EXCESS;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_PASSWORD;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_TYPE;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_URL;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_USERNAME;
|
||||
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_VALIDATION_QUERY;
|
||||
|
||||
/**
|
||||
* Create a DataSource on the SDB database.
|
||||
*/
|
||||
|
@ -53,8 +57,8 @@ public class SDBDataSource {
|
|||
cpds.setPassword(configProps.getProperty(PROPERTY_DB_PASSWORD));
|
||||
cpds.setMaxPoolSize(getMaxActive());
|
||||
cpds.setMinPoolSize(getMaxIdle());
|
||||
cpds.setMaxIdleTime(43200); // s
|
||||
cpds.setMaxIdleTimeExcessConnections(300);
|
||||
cpds.setMaxIdleTime(getMaxIdleTime());
|
||||
cpds.setMaxIdleTimeExcessConnections(getMaxIdleTimeExcess());
|
||||
cpds.setAcquireIncrement(5);
|
||||
cpds.setNumHelperThreads(6);
|
||||
cpds.setTestConnectionOnCheckout(DEFAULT_TESTONBORROW);
|
||||
|
@ -118,19 +122,30 @@ public class SDBDataSource {
|
|||
|
||||
private int getMaxIdle() {
|
||||
int maxIdleInt = Math.max(getMaxActive() / 4, DEFAULT_MAXIDLE);
|
||||
String maxIdleStr = configProps.getProperty(PROPERTY_DB_MAX_IDLE);
|
||||
return getPropertyAsInt(PROPERTY_DB_MAX_IDLE, maxIdleInt);
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(maxIdleStr)) {
|
||||
return maxIdleInt;
|
||||
private int getMaxIdleTime() {
|
||||
return getPropertyAsInt(PROPERTY_DB_MAX_IDLE_TIME, DEFAULT_MAX_IDLE_TIME);
|
||||
}
|
||||
|
||||
private int getMaxIdleTimeExcess() {
|
||||
return getPropertyAsInt(PROPERTY_DB_MAX_IDLE_TIME_EXCESS, DEFAULT_MAX_IDLE_TIME_EXCESS);
|
||||
}
|
||||
|
||||
private int getPropertyAsInt(String prop, int defaultValue) {
|
||||
String propStr = configProps.getProperty(prop);
|
||||
|
||||
if (StringUtils.isEmpty(propStr)) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
try {
|
||||
return Integer.parseInt(maxIdleStr);
|
||||
return Integer.parseInt(propStr);
|
||||
} catch (NumberFormatException nfe) {
|
||||
log.error("Unable to parse connection pool maxIdle setting "
|
||||
+ maxIdleStr + " as an integer");
|
||||
return maxIdleInt;
|
||||
+ propStr + " as an integer");
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue