Author: psteitz
Date: Mon May 9 06:36:59 2011
New Revision: 1100894
URL: http://svn.apache.org/viewvc?rev=1100894&view=rev
Log:
Added support for version 2 GOP, GKOP tests.
Added:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory2.java
(with props)
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactoryBase.java
(with props)
commons/sandbox/performance/trunk/src/pool/build.properties.sample
Modified:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java
commons/sandbox/performance/trunk/src/pool/build.xml
commons/sandbox/performance/trunk/src/pool/config-pool.xml
commons/sandbox/performance/trunk/src/pool/logging.properties
Modified:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java?rev=1100894&r1=1100893&r2=1100894&view=diff
==============================================================================
---
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
(original)
+++
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
Mon May 9 06:36:59 2011
@@ -21,8 +21,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
-import org.apache.commons.pool.ObjectPool;
-import org.apache.commons.pool.KeyedObjectPool;
+//import org.apache.commons.pool.ObjectPool;
+//import org.apache.commons.pool2.ObjectPool;
+//import org.apache.commons.pool.KeyedObjectPool;
+//import org.apache.commons.pool2.KeyedObjectPool;
import org.apache.commons.math.random.RandomData;
import org.apache.commons.math.random.RandomDataImpl;
import org.apache.commons.math.stat.descriptive.SummaryStatistics;
@@ -33,17 +35,24 @@ import org.apache.commons.performance.St
* <p>Client thread that borrows and returns objects from a pool in a loop.
* See {@link ClientThread ClientThread javadoc} for a description
* of how times between requests are computed. In addition to request latency,
- * pool numIdle and numActive statistics and stats on instance idle time are
tracked.</p>
+ * pool numIdle and numActive statistics and stats on instance idle time are
tracked.
+ * Constructors are provided for both 1.x and version 2 simple and keyed
pools.</p>
*
* <p>Note that this class is *not* threadsafe.</p>
*/
public class PoolClientThread extends ClientThread {
- /** Object pool (if keyed = false) */
- private final ObjectPool pool;
+ /** Version 1.x object pool (if keyed = false) */
+ private final org.apache.commons.pool.ObjectPool pool;
- /**Keyed pool (if keyed = true) */
- private final KeyedObjectPool keyedPool;
+ /** Version 1.x keyed pool (if keyed = true) */
+ private final org.apache.commons.pool.KeyedObjectPool keyedPool;
+
+ /** Version 2 object pool (if keyed = false) */
+ private final org.apache.commons.pool2.ObjectPool<Waiter> pool2;
+
+ /** Version 2 keyed pool (if keyed = true) */
+ private final org.apache.commons.pool2.KeyedObjectPool<Integer, Waiter>
keyedPool2;
/** Whether or not pool being tested is keyed */
private boolean keyed;
@@ -70,7 +79,7 @@ public class PoolClientThread extends Cl
private Waiter waiter = null;
/**
- * Create a pool client thread for an ObjectPool.
+ * Create a pool client thread for a version 1.x ObjectPool.
*
* @param iterations number of iterations
* @param minDelay minimum mean time between client requests
@@ -90,19 +99,22 @@ public class PoolClientThread extends Cl
public PoolClientThread(long iterations, long minDelay, long maxDelay,
double sigma, String delayType, long rampPeriod, long peakPeriod,
long troughPeriod, String cycleType, String rampType, Logger
logger,
- Statistics stats, ObjectPool pool, double samplingRate) {
+ Statistics stats, org.apache.commons.pool.ObjectPool pool,
+ double samplingRate) {
super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod,
peakPeriod, troughPeriod, cycleType,rampType, logger,
stats);
this.pool = pool;
+ this.pool2 = null;
+ this.keyedPool2 = null;
this.keyedPool = null;
this.keyed = false;
this.samplingRate = samplingRate;
}
/**
- * Create a pool client thread for a KeyedObjectPool.
+ * Create a pool client thread for a version 1.x KeyedObjectPool.
*
* @param iterations number of iterations
* @param minDelay minimum mean time between client requests
@@ -122,7 +134,8 @@ public class PoolClientThread extends Cl
public PoolClientThread(long iterations, long minDelay, long maxDelay,
double sigma, String delayType, long rampPeriod, long peakPeriod,
long troughPeriod, String cycleType, String rampType, Logger
logger,
- Statistics stats, KeyedObjectPool keyedPool, double samplingRate) {
+ Statistics stats, org.apache.commons.pool.KeyedObjectPool
keyedPool,
+ double samplingRate) {
super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod,
peakPeriod, troughPeriod, cycleType,rampType, logger,
@@ -130,6 +143,83 @@ public class PoolClientThread extends Cl
this.keyedPool = keyedPool;
this.pool = null;
+ this.pool2 = null;
+ this.keyedPool2 = null;
+ this.keyed = true;
+ this.samplingRate = samplingRate;
+ keys = new ArrayList<Integer>();
+ for (int i = 0; i < 20; i++) { //TODO: make number of keys configurable
+ keys.add(new Integer(i));
+ }
+ }
+
+ /**
+ * Create a pool client thread for a version 1.x ObjectPool.
+ *
+ * @param iterations number of iterations
+ * @param minDelay minimum mean time between client requests
+ * @param maxDelay maximum mean time between client requests
+ * @param delayType distribution of time between client requests
+ * @param rampPeriod ramp period of cycle for cyclic load
+ * @param peakPeriod peak period of cycle for cyclic load
+ * @param troughPeriod trough period of cycle for cyclic load
+ * @param cycleType type of cycle for mean delay
+ * @param rampType type of ramp (linear or random jumps)
+ * @param logger common logger shared by all clients
+ * @param stats Statistics container
+ * @param pool ObjectPool
+ * @param samplingRate proportion of requests for which numIdle and
numActive
+ * will be sampled for statistical analysis
+ */
+ public PoolClientThread(long iterations, long minDelay, long maxDelay,
+ double sigma, String delayType, long rampPeriod, long peakPeriod,
+ long troughPeriod, String cycleType, String rampType, Logger
logger,
+ Statistics stats, org.apache.commons.pool2.ObjectPool<Waiter> pool,
+ double samplingRate) {
+
+ super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod,
+ peakPeriod, troughPeriod, cycleType,rampType, logger,
+ stats);
+ this.pool2 = pool;
+ this.pool = null;
+ this.keyedPool2 = null;
+ this.keyedPool = null;
+ this.keyed = false;
+ this.samplingRate = samplingRate;
+ }
+
+ /**
+ * Create a pool client thread for a version 1.x KeyedObjectPool.
+ *
+ * @param iterations number of iterations
+ * @param minDelay minimum mean time between client requests
+ * @param maxDelay maximum mean time between client requests
+ * @param delayType distribution of time between client requests
+ * @param rampPeriod ramp period of cycle for cyclic load
+ * @param peakPeriod peak period of cycle for cyclic load
+ * @param troughPeriod trough period of cycle for cyclic load
+ * @param cycleType type of cycle for mean delay
+ * @param rampType type of ramp (linear or random jumps)
+ * @param logger common logger shared by all clients
+ * @param stats Statistics container
+ * @param keyedPool KeyedObjectPool
+ * @param samplingRate proportion of requests for which numIdle and
numActive
+ * will be sampled for statistical analysis
+ */
+ public PoolClientThread(long iterations, long minDelay, long maxDelay,
+ double sigma, String delayType, long rampPeriod, long peakPeriod,
+ long troughPeriod, String cycleType, String rampType, Logger
logger,
+ Statistics stats,
org.apache.commons.pool2.KeyedObjectPool<Integer, Waiter> keyedPool,
+ double samplingRate) {
+
+ super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod,
+ peakPeriod, troughPeriod, cycleType,rampType, logger,
+ stats);
+
+ this.keyedPool2 = keyedPool;
+ this.pool = null;
+ this.pool2 = null;
+ this.keyedPool = null;
this.keyed = true;
this.samplingRate = samplingRate;
keys = new ArrayList<Integer>();
@@ -142,13 +232,23 @@ public class PoolClientThread extends Cl
public void execute() throws Exception {
if (keyed) {
Integer key = keys.get(randomData.nextInt(0, 19));
- waiter = (Waiter) keyedPool.borrowObject(key);
+ waiter = keyedPool2 == null ? (Waiter) keyedPool.borrowObject(key) :
+ keyedPool2.borrowObject(key);
waiter.doWait();
- keyedPool.returnObject(key, waiter);
+ if (keyedPool2 == null) {
+ keyedPool.returnObject(key, waiter);
+ } else {
+ keyedPool2.returnObject(key, waiter);
+ }
} else {
- waiter = (Waiter) pool.borrowObject();
+ waiter = pool2 == null ? (Waiter) pool.borrowObject() :
+ pool2.borrowObject();
waiter.doWait();
- pool.returnObject(waiter);
+ if (pool2 == null) {
+ pool.returnObject(waiter);
+ } else {
+ pool2.returnObject(waiter);
+ }
}
}
@@ -156,11 +256,15 @@ public class PoolClientThread extends Cl
// Capture pool metrics
if (randomData.nextUniform(0, 1) < samplingRate) {
if (keyed) {
- numIdleStats.addValue(keyedPool.getNumIdle());
- numActiveStats.addValue(keyedPool.getNumActive());
+ numIdleStats.addValue(keyedPool2 == null ?
keyedPool.getNumIdle() :
+ keyedPool2.getNumIdle());
+ numActiveStats.addValue(keyedPool2 == null ?
keyedPool.getNumActive() :
+ keyedPool2.getNumActive());
} else {
- numIdleStats.addValue(pool.getNumIdle());
- numActiveStats.addValue(pool.getNumActive());
+ numIdleStats.addValue(pool2 == null ? pool.getNumIdle() :
+ pool2.getNumIdle());
+ numActiveStats.addValue(pool2 == null ? pool.getNumActive() :
+ pool2.getNumActive());
}
}
if (waiter != null) {
Modified:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java?rev=1100894&r1=1100893&r2=1100894&view=diff
==============================================================================
---
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
(original)
+++
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
Mon May 9 06:36:59 2011
@@ -20,10 +20,8 @@ package org.apache.commons.performance.p
import java.util.logging.Logger;
import org.apache.commons.dbcp.AbandonedConfig;
import org.apache.commons.dbcp.AbandonedObjectPool;
-import org.apache.commons.pool.impl.GenericObjectPool;
import org.apache.commons.pool.impl.StackObjectPool;
import org.apache.commons.pool.impl.SoftReferenceObjectPool;
-import org.apache.commons.pool.impl.GenericKeyedObjectPool;
import org.apache.commons.pool.impl.StackKeyedObjectPool;
import org.apache.commons.performance.ConfigurationException;
import org.apache.commons.performance.ClientThread;
@@ -39,8 +37,10 @@ import org.apache.commons.performance.St
public class PoolSoak extends LoadGenerator {
// Pool instances
- private GenericObjectPool genericObjectPool;
- private GenericKeyedObjectPool genericKeyedObjectPool;
+ private org.apache.commons.pool.impl.GenericObjectPool genericObjectPool;
+ private org.apache.commons.pool.impl.GenericKeyedObjectPool
genericKeyedObjectPool;
+ private org.apache.commons.pool2.impl.GenericObjectPool<Waiter>
genericObjectPool2;
+ private org.apache.commons.pool2.impl.GenericKeyedObjectPool<Integer,
Waiter> genericKeyedObjectPool2;
private StackObjectPool stackObjectPool;
private SoftReferenceObjectPool softReferenceObjectPool;
private StackKeyedObjectPool stackKeyedObjectPool;
@@ -148,9 +148,13 @@ public class PoolSoak extends LoadGenera
makeLatency, passivateLatency, validateLatency, waiterLatency,
maxActive, maxActivePerKey, passivateInvalidationProbability);
+ WaiterFactory2 factory2 = new WaiterFactory2(activateLatency,
destroyLatency,
+ makeLatency, passivateLatency, validateLatency, waiterLatency,
+ maxActive, maxActivePerKey, passivateInvalidationProbability);
+
// Create object pool
if (poolType.equals("GenericObjectPool")) {
- genericObjectPool = new GenericObjectPool(factory);
+ genericObjectPool = new
org.apache.commons.pool.impl.GenericObjectPool(factory);
genericObjectPool.setMaxActive(maxActive);
genericObjectPool.setWhenExhaustedAction(exhaustedAction);
genericObjectPool.setMaxWait(maxWait);
@@ -163,9 +167,24 @@ public class PoolSoak extends LoadGenera
genericObjectPool.setNumTestsPerEvictionRun(testsPerEviction);
genericObjectPool.setMinEvictableIdleTimeMillis(idleTimeout);
genericObjectPool.setTestWhileIdle(testWhileIdle);
- //genericObjectPool.setLifo(lifo);
+ genericObjectPool.setLifo(lifo);
+ } else if (poolType.equals("GenericObjectPool2")) {
+ genericObjectPool2 = new
org.apache.commons.pool2.impl.GenericObjectPool<Waiter>(factory2);
+ genericObjectPool2.setMaxActive(maxActive);
+ genericObjectPool2.setWhenExhaustedAction(exhaustedAction);
+ genericObjectPool2.setMaxWait(maxWait);
+ genericObjectPool2.setMaxIdle(maxIdle);
+ genericObjectPool2.setMinIdle(minIdle);
+ genericObjectPool2.setTestOnBorrow(testOnBorrow);
+ genericObjectPool2.setTestOnReturn(testOnReturn);
+ genericObjectPool2.setTimeBetweenEvictionRunsMillis(
+ timeBetweenEvictions);
+ genericObjectPool2.setNumTestsPerEvictionRun(testsPerEviction);
+ genericObjectPool2.setMinEvictableIdleTimeMillis(idleTimeout);
+ genericObjectPool2.setTestWhileIdle(testWhileIdle);
+ genericObjectPool2.setLifo(lifo);
} else if (poolType.equals("AbandonedObjectPool")) {
- genericObjectPool = new AbandonedObjectPool(null,abandonedConfig);
+ genericObjectPool = new
AbandonedObjectPool(factory,abandonedConfig);
genericObjectPool.setMaxActive(maxActive);
genericObjectPool.setWhenExhaustedAction(exhaustedAction);
genericObjectPool.setMaxWait(maxWait);
@@ -178,10 +197,9 @@ public class PoolSoak extends LoadGenera
genericObjectPool.setNumTestsPerEvictionRun(testsPerEviction);
genericObjectPool.setMinEvictableIdleTimeMillis(idleTimeout);
genericObjectPool.setTestWhileIdle(testWhileIdle);
- //genericObjectPool.setLifo(lifo);
- genericObjectPool.setFactory(factory);
+ genericObjectPool.setLifo(lifo);
} else if (poolType.equals("GenericKeyedObjectPool")) {
- genericKeyedObjectPool = new GenericKeyedObjectPool();
+ genericKeyedObjectPool = new
org.apache.commons.pool.impl.GenericKeyedObjectPool(factory);
genericKeyedObjectPool.setMaxActive(maxActivePerKey);
genericKeyedObjectPool.setMaxTotal(maxActive);
genericKeyedObjectPool.setWhenExhaustedAction(exhaustedAction);
@@ -195,17 +213,30 @@ public class PoolSoak extends LoadGenera
genericKeyedObjectPool.setNumTestsPerEvictionRun(testsPerEviction);
genericKeyedObjectPool.setMinEvictableIdleTimeMillis(idleTimeout);
genericKeyedObjectPool.setTestWhileIdle(testWhileIdle);
- //genericKeyedObjectPool.setLifo(lifo);
- genericKeyedObjectPool.setFactory(factory);
+ genericKeyedObjectPool.setLifo(lifo);
+ } else if (poolType.equals("GenericKeyedObjectPool2")) {
+ genericKeyedObjectPool2 =
+ new
org.apache.commons.pool2.impl.GenericKeyedObjectPool<Integer, Waiter>(factory2);
+ genericKeyedObjectPool2.setMaxActive(maxActivePerKey);
+ genericKeyedObjectPool2.setMaxTotal(maxActive);
+ genericKeyedObjectPool2.setWhenExhaustedAction(exhaustedAction);
+ genericKeyedObjectPool2.setMaxWait(maxWait);
+ genericKeyedObjectPool2.setMaxIdle(maxIdle);
+ genericKeyedObjectPool2.setMinIdle(minIdle);
+ genericKeyedObjectPool2.setTestOnBorrow(testOnBorrow);
+ genericKeyedObjectPool2.setTestOnReturn(testOnReturn);
+ genericKeyedObjectPool2.setTimeBetweenEvictionRunsMillis(
+ timeBetweenEvictions);
+
genericKeyedObjectPool2.setNumTestsPerEvictionRun(testsPerEviction);
+ genericKeyedObjectPool2.setMinEvictableIdleTimeMillis(idleTimeout);
+ genericKeyedObjectPool2.setTestWhileIdle(testWhileIdle);
+ genericKeyedObjectPool2.setLifo(lifo);
} else if (poolType.equals("StackObjectPool")) {
- stackObjectPool = new StackObjectPool();
- stackObjectPool.setFactory(factory);
+ stackObjectPool = new StackObjectPool(factory);
} else if (poolType.equals("SoftReferenceObjectPool")) {
- softReferenceObjectPool = new SoftReferenceObjectPool();
- softReferenceObjectPool.setFactory(factory);
+ softReferenceObjectPool = new SoftReferenceObjectPool(factory);
} else if (poolType.equals("StackKeyedObjectPool")) {
- stackKeyedObjectPool = new StackKeyedObjectPool();
- stackKeyedObjectPool.setFactory(factory);
+ stackKeyedObjectPool = new StackKeyedObjectPool(factory);
} else {
throw new ConfigurationException(
"invalid pool type configuration: " + poolType);
@@ -224,6 +255,12 @@ public class PoolSoak extends LoadGenera
if (genericKeyedObjectPool != null) {
genericKeyedObjectPool.close();
}
+ if (genericObjectPool2 != null) {
+ genericObjectPool2.close();
+ }
+ if (genericKeyedObjectPool2 != null) {
+ genericKeyedObjectPool2.close();
+ }
if (stackObjectPool != null) {
stackObjectPool.close();
}
@@ -254,6 +291,18 @@ public class PoolSoak extends LoadGenera
cycleType, rampType, logger, stats,
genericKeyedObjectPool, samplingRate);
}
+ if (poolType.equals("GenericObjectPool2")) {
+ return new PoolClientThread(iterations, minDelay, maxDelay,
+ sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
+ cycleType, rampType, logger, stats, genericObjectPool2,
+ samplingRate);
+ }
+ if (poolType.equals("GenericKeyedObjectPool2")) {
+ return new PoolClientThread(iterations, minDelay, maxDelay,
+ sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
+ cycleType, rampType, logger, stats,
+ genericKeyedObjectPool2, samplingRate);
+ }
if (poolType.equals("StackKeyedObjectPool")) {
return new PoolClientThread(iterations, minDelay, maxDelay,
sigma, delayType, rampPeriod, peakPeriod, troughPeriod,
@@ -314,11 +363,11 @@ public class PoolSoak extends LoadGenera
this.lifo = Boolean.parseBoolean(lifo);
this.poolType = type;
if (exhaustedAction.equals("block")) {
- this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
+ this.exhaustedAction =
org.apache.commons.pool.impl.GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
} else if (exhaustedAction.equals("fail")) {
- this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
+ this.exhaustedAction =
org.apache.commons.pool.impl.GenericObjectPool.WHEN_EXHAUSTED_FAIL;
} else if (exhaustedAction.equals("grow")) {
- this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
+ this.exhaustedAction =
org.apache.commons.pool.impl.GenericObjectPool.WHEN_EXHAUSTED_GROW;
} else {
throw new ConfigurationException(
"Bad configuration setting for exhausted action: "
@@ -337,11 +386,11 @@ public class PoolSoak extends LoadGenera
}
// Pool getters for unit tests
- protected GenericObjectPool getGenericObjectPool() {
+ protected org.apache.commons.pool.impl.GenericObjectPool
getGenericObjectPool() {
return genericObjectPool;
}
- protected GenericKeyedObjectPool getGenericKeyedObjectPool() {
+ protected org.apache.commons.pool.impl.GenericKeyedObjectPool
getGenericKeyedObjectPool() {
return genericKeyedObjectPool;
}
Modified:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java?rev=1100894&r1=1100893&r2=1100894&view=diff
==============================================================================
---
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java
(original)
+++
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java
Mon May 9 06:36:59 2011
@@ -17,74 +17,22 @@
package org.apache.commons.performance.pool;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Iterator;
-import java.util.logging.Logger;
-import java.util.logging.Level;
import java.util.concurrent.atomic.AtomicInteger;
-
import org.apache.commons.pool.PoolableObjectFactory;
import org.apache.commons.pool.KeyedPoolableObjectFactory;
/**
- * Object factory with configurable latencies for object lifecycle methods.
- *
+ * Version 1.x object factory with configurable latencies for object lifecycle
methods.
*/
-public class WaiterFactory implements PoolableObjectFactory,
-KeyedPoolableObjectFactory {
-
- // TODO: implement protected getters so these can be stochastic
- /** Latency of activateObject */
- private final long activateLatency;
-
- /** Latency of destroyObject */
- private final long destroyLatency;
-
- /** Latency of makeObject */
- private final long makeLatency;
-
- /** Latency of passivateObject */
- private final long passivateLatency;
-
- /** Latency of validateObject */
- private final long validateLatency;
-
- /** Latency of doWait for Waiter instances created by this factory */
- private final long waiterLatency;
-
- /** Probability that passivation will invalidate Waiter instances */
- private final double passivateInvalidationProbability;
-
- /** Count of (makes - destroys) since last reset */
- private long activeCount = 0;
-
- /** Count of (makes - destroys) per key since last reset */
- private Map<Object, AtomicInteger> activeCounts =
- new HashMap<Object, AtomicInteger>();
-
- /** Maximum of (makes - destroys) - if exceeded IllegalStateException */
- private final long maxActive;
-
- /** Maximum of (makes - destroys) per key */
- private final long maxActivePerKey;
-
- protected static final Logger logger =
- Logger.getLogger(WaiterFactory.class.getName());
+public class WaiterFactory extends WaiterFactoryBase implements
PoolableObjectFactory, KeyedPoolableObjectFactory {
public WaiterFactory(long activateLatency, long destroyLatency,
long makeLatency, long passivateLatency, long validateLatency,
long waiterLatency,long maxActive, long maxActivePerKey,
double passivateInvalidationProbability) {
- this.activateLatency = activateLatency;
- this.destroyLatency = destroyLatency;
- this.makeLatency = makeLatency;
- this.passivateLatency = passivateLatency;
- this.validateLatency = validateLatency;
- this.waiterLatency = waiterLatency;
- this.maxActive = maxActive;
- this.maxActivePerKey = maxActivePerKey;
- this.passivateInvalidationProbability =
passivateInvalidationProbability;
+ super(activateLatency, destroyLatency, makeLatency,
+ passivateLatency, validateLatency, waiterLatency, maxActive,
+ maxActivePerKey, passivateInvalidationProbability);
}
public WaiterFactory(long activateLatency, long destroyLatency,
@@ -102,125 +50,51 @@ KeyedPoolableObjectFactory {
}
public void activateObject(Object obj) throws Exception {
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest("activate");
- }
- doWait(activateLatency);
- ((Waiter) obj).setActive(true);
+ activate((Waiter) obj);
}
public void destroyObject(Object obj) throws Exception {
- if (logger.isLoggable(Level.FINE)) {
- logger.fine("destroy");
- }
- doWait(destroyLatency);
- ((Waiter) obj).setValid(false);
- ((Waiter) obj).setActive(false);
- // Decrement *after* destroy
- synchronized (this) {
- activeCount--;
- }
+ destroy((Waiter) obj);
}
-
+
public Object makeObject() throws Exception {
- // Increment and test *before* make
- synchronized (this) {
- if (activeCount >= maxActive) {
- throw new IllegalStateException("Too many active instances: " +
- activeCount + " in circulation with maxActive = " + maxActive);
- } else {
- activeCount++;
- }
- }
- if (logger.isLoggable(Level.FINE)) {
- logger.fine("makeObject");
- }
- doWait(makeLatency);
- return new Waiter(false, true, waiterLatency);
- }
-
- public void passivateObject(Object arg0) throws Exception {
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest("passivate");
- }
- ((Waiter) arg0).setActive(false);
- doWait(passivateLatency);
- if (Math.random() < passivateInvalidationProbability) {
- ((Waiter) arg0).setValid(false);
- }
+ return make();
}
- public boolean validateObject(Object arg0) {
- if (logger.isLoggable(Level.FINE)) {
- logger.fine("validate");
- }
- doWait(validateLatency);
- return ((Waiter) arg0).isValid();
- }
-
- protected void doWait(long latency) {
- try {
- Thread.sleep(latency);
- } catch (InterruptedException ex) {
- // ignore
- }
+ public void passivateObject(Object obj) throws Exception {
+ passivate((Waiter) obj);
}
- public synchronized void reset() {
- activeCount = 0;
- if (activeCounts.isEmpty()) {
- return;
- }
- Iterator it = activeCounts.keySet().iterator();
- while (it.hasNext()) {
- ((AtomicInteger) activeCounts.get(it.next())).getAndSet(0);
- }
- }
- /**
- * @return the maxActive
- */
- public synchronized long getMaxActive() {
- return maxActive;
+ public boolean validateObject(Object obj) {
+ return validate((Waiter) obj);
}
// KeyedPoolableObjectFactory methods
public void activateObject(Object key, Object obj) throws Exception {
- activateObject(obj);
+ activate((Waiter) obj);
}
public void destroyObject(Object key, Object obj) throws Exception {
- destroyObject(obj);
+ destroy((Waiter) obj);
synchronized (this) {
((AtomicInteger) activeCounts.get(key)).getAndDecrement();
}
}
public Object makeObject(Object key) throws Exception {
- synchronized (this) {
- AtomicInteger count = (AtomicInteger) activeCounts.get(key);
- if (count == null) {
- count = new AtomicInteger(1);
- activeCounts.put(key, count);
- } else {
- if (count.get() >= maxActivePerKey) {
- throw new IllegalStateException("Too many active " +
- "instances for key = " + key + ": " + count.get() +
- " in circulation " + "with maxActivePerKey = " +
- maxActivePerKey);
- } else {
- count.incrementAndGet();
- }
- }
- }
- return makeObject();
+ return makeObject((Integer) key);
+ }
+
+ public Object makeObject(Integer key) throws Exception {
+ return make(key);
}
public void passivateObject(Object key, Object obj) throws Exception {
passivateObject(obj);
}
-
+
public boolean validateObject(Object key, Object obj) {
return validateObject(obj);
}
Added:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory2.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory2.java?rev=1100894&view=auto
==============================================================================
---
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory2.java
(added)
+++
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory2.java
Mon May 9 06:36:59 2011
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.performance.pool;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.commons.pool2.PoolableObjectFactory;
+import org.apache.commons.pool2.KeyedPoolableObjectFactory;
+
+/**
+ * Version 2 object factory with configurable latencies for object lifecycle
methods.
+ */
+public class WaiterFactory2 extends WaiterFactoryBase implements
+PoolableObjectFactory<Waiter>, KeyedPoolableObjectFactory<Integer, Waiter> {
+
+ public WaiterFactory2(long activateLatency, long destroyLatency,
+ long makeLatency, long passivateLatency, long validateLatency,
+ long waiterLatency,long maxActive, long maxActivePerKey,
+ double passivateInvalidationProbability) {
+ super(activateLatency, destroyLatency, makeLatency,
+ passivateLatency, validateLatency, waiterLatency, maxActive,
+ maxActivePerKey, passivateInvalidationProbability);
+ }
+
+ public WaiterFactory2(long activateLatency, long destroyLatency,
+ long makeLatency, long passivateLatency, long validateLatency,
+ long waiterLatency) {
+ this(activateLatency, destroyLatency, makeLatency, passivateLatency,
+ validateLatency, waiterLatency, Long.MAX_VALUE,
Long.MAX_VALUE, 0);
+ }
+
+ public WaiterFactory2(long activateLatency, long destroyLatency,
+ long makeLatency, long passivateLatency, long validateLatency,
+ long waiterLatency,long maxActive) {
+ this(activateLatency, destroyLatency, makeLatency, passivateLatency,
+ validateLatency, waiterLatency, maxActive, Long.MAX_VALUE, 0);
+ }
+
+ public void activateObject(Waiter waiter) throws Exception {
+ activate(waiter);
+ }
+
+ public void destroyObject(Waiter waiter) throws Exception {
+ destroy(waiter);
+ }
+
+ public Waiter makeObject() throws Exception {
+ return make();
+ }
+
+ public void passivateObject(Waiter waiter) throws Exception {
+ passivate(waiter);
+ }
+
+ public boolean validateObject(Waiter waiter) {
+ return validate(waiter);
+ }
+
+
+ public void activateObject(Integer key, Waiter waiter) throws Exception {
+ activate(waiter);
+ }
+
+ public void destroyObject(Integer key, Waiter waiter) throws Exception {
+ destroy(waiter);
+ synchronized (this) {
+ ((AtomicInteger) activeCounts.get(key)).getAndDecrement();
+ }
+ }
+
+ public Waiter makeObject(Integer key) throws Exception {
+ return make(key);
+ }
+
+ public void passivateObject(Integer key, Waiter waiter) throws Exception {
+ passivateObject(waiter);
+ }
+
+ public boolean validateObject(Integer key, Waiter waiter) {
+ return validateObject(waiter);
+ }
+
+}
Propchange:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory2.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory2.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory2.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactoryBase.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactoryBase.java?rev=1100894&view=auto
==============================================================================
---
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactoryBase.java
(added)
+++
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactoryBase.java
Mon May 9 06:36:59 2011
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.performance.pool;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Iterator;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Base for version 1.x and 2 Waiter factories
+ */
+public class WaiterFactoryBase {
+
+ // TODO: implement protected getters so these can be stochastic
+ /** Latency of activateObject */
+ private final long activateLatency;
+
+ /** Latency of destroyObject */
+ private final long destroyLatency;
+
+ /** Latency of makeObject */
+ private final long makeLatency;
+
+ /** Latency of passivateObject */
+ private final long passivateLatency;
+
+ /** Latency of validateObject */
+ private final long validateLatency;
+
+ /** Latency of doWait for Waiter instances created by this factory */
+ private final long waiterLatency;
+
+ /** Probability that passivation will invalidate Waiter instances */
+ private final double passivateInvalidationProbability;
+
+ /** Count of (makes - destroys) since last reset */
+ private long activeCount = 0;
+
+ /** Count of (makes - destroys) per key since last reset */
+ protected Map<Integer, AtomicInteger> activeCounts =
+ new HashMap<Integer, AtomicInteger>();
+
+ /** Maximum of (makes - destroys) - if exceeded IllegalStateException */
+ private final long maxActive;
+
+ /** Maximum of (makes - destroys) per key */
+ private final long maxActivePerKey;
+
+ protected static final Logger logger =
+ Logger.getLogger(WaiterFactoryBase.class.getName());
+
+ public WaiterFactoryBase(long activateLatency, long destroyLatency,
+ long makeLatency, long passivateLatency, long validateLatency,
+ long waiterLatency,long maxActive, long maxActivePerKey,
+ double passivateInvalidationProbability) {
+ this.activateLatency = activateLatency;
+ this.destroyLatency = destroyLatency;
+ this.makeLatency = makeLatency;
+ this.passivateLatency = passivateLatency;
+ this.validateLatency = validateLatency;
+ this.waiterLatency = waiterLatency;
+ this.maxActive = maxActive;
+ this.maxActivePerKey = maxActivePerKey;
+ this.passivateInvalidationProbability =
passivateInvalidationProbability;
+ }
+
+ public WaiterFactoryBase(long activateLatency, long destroyLatency,
+ long makeLatency, long passivateLatency, long validateLatency,
+ long waiterLatency) {
+ this(activateLatency, destroyLatency, makeLatency, passivateLatency,
+ validateLatency, waiterLatency, Long.MAX_VALUE,
Long.MAX_VALUE, 0);
+ }
+
+ public WaiterFactoryBase(long activateLatency, long destroyLatency,
+ long makeLatency, long passivateLatency, long validateLatency,
+ long waiterLatency,long maxActive) {
+ this(activateLatency, destroyLatency, makeLatency, passivateLatency,
+ validateLatency, waiterLatency, maxActive, Long.MAX_VALUE, 0);
+ }
+
+ protected void activate(Waiter waiter) {
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest("activate");
+ }
+ doWait(activateLatency);
+ waiter.setActive(true);
+ }
+
+ protected void destroy(Waiter waiter) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("destroy");
+ }
+ doWait(destroyLatency);
+ waiter.setValid(false);
+ waiter.setActive(false);
+ // Decrement *after* destroy
+ synchronized (this) {
+ activeCount--;
+ }
+ }
+
+ public Waiter make() throws Exception {
+ // Increment and test *before* make
+ synchronized (this) {
+ if (activeCount >= maxActive) {
+ throw new IllegalStateException("Too many active instances: " +
+ activeCount + " in circulation with maxActive = " + maxActive);
+ } else {
+ activeCount++;
+ }
+ }
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("makeObject");
+ }
+ doWait(makeLatency);
+ return new Waiter(false, true, waiterLatency);
+ }
+
+ protected void passivate(Waiter waiter) {
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest("passivate");
+ }
+ waiter.setActive(false);
+ doWait(passivateLatency);
+ if (Math.random() < passivateInvalidationProbability) {
+ waiter.setValid(false);
+ }
+ }
+
+ protected boolean validate(Waiter waiter) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("validate");
+ }
+ doWait(validateLatency);
+ return waiter.isValid();
+ }
+
+ protected void doWait(long latency) {
+ try {
+ Thread.sleep(latency);
+ } catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+
+ public synchronized void reset() {
+ activeCount = 0;
+ if (activeCounts.isEmpty()) {
+ return;
+ }
+ Iterator<Integer> it = activeCounts.keySet().iterator();
+ while (it.hasNext()) {
+ ((AtomicInteger) activeCounts.get(it.next())).getAndSet(0);
+ }
+ }
+
+ /**
+ * @return the maxActive
+ */
+ public synchronized long getMaxActive() {
+ return maxActive;
+ }
+
+ public Waiter make(Integer key) throws Exception {
+ synchronized (this) {
+ AtomicInteger count = (AtomicInteger) activeCounts.get(key);
+ if (count == null) {
+ count = new AtomicInteger(1);
+ activeCounts.put(key, count);
+ } else {
+ if (count.get() >= maxActivePerKey) {
+ throw new IllegalStateException("Too many active " +
+ "instances for key = " + key + ": " + count.get() +
+ " in circulation " + "with maxActivePerKey = " +
+ maxActivePerKey);
+ } else {
+ count.incrementAndGet();
+ }
+ }
+ }
+ return make();
+ }
+
+}
Propchange:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactoryBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactoryBase.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactoryBase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/performance/trunk/src/pool/build.properties.sample
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/pool/build.properties.sample?rev=1100894&view=auto
==============================================================================
--- commons/sandbox/performance/trunk/src/pool/build.properties.sample (added)
+++ commons/sandbox/performance/trunk/src/pool/build.properties.sample Mon May
9 06:36:59 2011
@@ -0,0 +1,26 @@
+###############################################################################
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+###############################################################################
+
+# Remote maven repository
+mavenRepo=http://repo1.maven.org/maven2
+
+# Replace with full path to versions of pool, dbcp jars you want to test with
+pool-jar=${user.home}/.m2/repository/commons-pool/commons-pool/1.5.6/commons-pool-1.5.6.jar
+pool2-jar=${user.home}/.m2/repository/org/apache/commons/commons-pool2/2.0-SNAPSHOT/commons-pool2-2.0-SNAPSHOT.jar
+dbcp-jar=${user.home}/.m2/repository/commons-dbcp/commons-dbcp/1.3/commons-dbcp-1.3.jar
+
Modified: commons/sandbox/performance/trunk/src/pool/build.xml
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/pool/build.xml?rev=1100894&r1=1100893&r2=1100894&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/pool/build.xml (original)
+++ commons/sandbox/performance/trunk/src/pool/build.xml Mon May 9 06:36:59
2011
@@ -30,6 +30,7 @@
<path id="compile.classpath">
<pathelement location="${pool-jar}"/>
+ <pathelement location="${pool2-jar}"/>
<pathelement location="${dbcp-jar}"/>
<fileset dir="${lib}">
<include name="*.jar"/>
Modified: commons/sandbox/performance/trunk/src/pool/config-pool.xml
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/pool/config-pool.xml?rev=1100894&r1=1100893&r2=1100894&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/pool/config-pool.xml (original)
+++ commons/sandbox/performance/trunk/src/pool/config-pool.xml Mon May 9
06:36:59 2011
@@ -33,8 +33,9 @@
<pool>
<!-- GenericObjectPool, AbandonedObjectPool, GenericKeyedObjectPool
- StackObjectPool, StackKeyedObjectPool, SoftReferenceObjectPool -->
- <type>GenericObjectPool</type>
+ StackObjectPool, StackKeyedObjectPool, SoftReferenceObjectPool.
+ GenericObjectPool2, GenericKeyedObjectPool2 (version 2 pools) -->
+ <type>GenericObjectPool2</type>
<max-active>100</max-active>
<max-idle>10</max-idle>
<min-idle>5</min-idle>
@@ -67,7 +68,7 @@
<delay-max>2000</delay-max>
<delay-sigma>100</delay-sigma>
<!-- constant, gaussian, or poisson -->
- <delay-type>poisson</delay-type>
+ <delay-type>constant</delay-type>
<!-- none, linear, random -->
<ramp-type>linear</ramp-type>
<ramp-period>2000</ramp-period>
Modified: commons/sandbox/performance/trunk/src/pool/logging.properties
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/pool/logging.properties?rev=1100894&r1=1100893&r2=1100894&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/pool/logging.properties (original)
+++ commons/sandbox/performance/trunk/src/pool/logging.properties Mon May 9
06:36:59 2011
@@ -21,6 +21,7 @@ handlers=java.util.logging.FileHandler,
.level=WARNING
org.apache.commons.pool.level=FINE
+org.apache.commons.pool2.level=FINE
org.apache.commons.performance.level=INFO
java.util.logging.ConsoleHandler.level=SEVERE