Author: psteitz
Date: Sun Jul 22 20:21:37 2007
New Revision: 558593
URL: http://svn.apache.org/viewvc?view=rev&rev=558593
Log:
Initial commit - pool + README
Added:
jakarta/commons/sandbox/performance/trunk/README.txt
jakarta/commons/sandbox/performance/trunk/build-pool.xml
jakarta/commons/sandbox/performance/trunk/config-pool.xml
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolTest.java
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/Waiter.java
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java
Added: jakarta/commons/sandbox/performance/trunk/README.txt
URL:
http://svn.apache.org/viewvc/jakarta/commons/sandbox/performance/trunk/README.txt?view=auto&rev=558593
==============================================================================
--- jakarta/commons/sandbox/performance/trunk/README.txt (added)
+++ jakarta/commons/sandbox/performance/trunk/README.txt Sun Jul 22 20:21:37
2007
@@ -0,0 +1,54 @@
+=== Compiling and running ===
+
+To run the dbcp tests, edit configuration in config-dbcp.xml, make sure the
+configured database is running and accepting connections, and run
+ant -f build-dbcp.xml. The first time you run against a configured database,
+a table with 10000 rows will be created and populated with random data.
+You also need to specify the path to the jdbc driver jar in build.properties.
+Edit logging.properties to provide a real path for the log file or otherwise
+clean up the filespec there.
+
+To run the pool tests, use config-pool.xml and ant -f build-pool.xml and
+again edit logging.properties to direct the log file.
+
+=== Parameters ===
+
+In addition to pool / dbcp parameters, the client request frequency and other
+parameters can be set. These are (poorly) documented in the config files or
+in javadoc for the ClientThread or other classes. The min-delay and max-delay
+determine how frequently client threads will submit requests. In the simplest
+case, if delay-type is constant, the client will try to submit a request every
+min-delay milliseconds. Ramping and oscillating loads are also supported. See
+the javadoc for ClientThread.nextDelay for details.
+
+=== Statistics ===
+
+Runs consist of client threads submitting requests in a loop, with configurable
+delays in between. Statistics on latency of the core request operation are
+gathered by thread and overall. The "number of misses" reported per thread
+is the number of times that the request operation itself took longer than the
+presribed interarrival time for the thread (e.g. the thread is supposed to send
+one request each 100ms, but it has to wait 150ms for a response). If the number
+of misses is a significant percentage of the number of iterations, you should
+consider increasing the number of service nodes (pool maxActive) or decreasing
+the delay-min / delay-max.
+
+=== TODO ===
+
+* Property representation and management is poor. Configuration objects should
+ be defined and Digester should create and populate configuration beans.
+
+* There is still a fair amount of duplicated / similar code between pool and
+ dbcp. This should all be factored out and moved to the performance package.
+
+* Ant build is lame. To change pool impls used - e.g. to grab latest snap -
+ you need to hack the get-deps. This should be cleaned up.
+
+* More pool types need to be supported.
+
+* WaiterFactory should support stochastic latencies for lifecycle methods
+ similar to ClientThread.nextDelay. Probably nextDelay belongs in a separate
+ latency generation class.
+
+* TESTS!!! There are no Junit tests. wtf?
+
Added: jakarta/commons/sandbox/performance/trunk/build-pool.xml
URL:
http://svn.apache.org/viewvc/jakarta/commons/sandbox/performance/trunk/build-pool.xml?view=auto&rev=558593
==============================================================================
--- jakarta/commons/sandbox/performance/trunk/build-pool.xml (added)
+++ jakarta/commons/sandbox/performance/trunk/build-pool.xml Sun Jul 22
20:21:37 2007
@@ -0,0 +1,116 @@
+<!--
+/*
+ * 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.
+ */
+ -->
+
+<project name="DBCPTest" default="run" basedir=".">
+
+ <property name="src" location="src"/>
+ <property name="build" location="build"/>
+ <property name="lib" location="lib"/>
+
+ <property name="component-propfile" value="${basedir}/build.properties"/>
+ <property file="${component-propfile}"/>
+
+ <path id="compile.classpath">
+ <fileset dir="${lib}">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+
+ <path id="run.classpath">
+ <pathelement path="${build}"/>
+ <pathelement path="${java.class.path}"/>
+ <path refid="compile.classpath" />
+ </path>
+
+ <target name="init">
+ <mkdir dir="${build}"/>
+ <mkdir dir="${lib}"/>
+ </target>
+
+ <target name="get-collections">
+ <get
+
src="${mavenRepo}/commons-collections/commons-collections/3.1/commons-collections-3.1.jar"
+ dest="${lib}/commons-collections-3.1.jar"
+ usetimestamp="true"/>
+ </target>
+
+ <target name="get-beanutils">
+ <get
+
src="${mavenRepo}/commons-beanutils/commons-beanutils/1.6.1/commons-beanutils-1.6.1.jar"
+ dest="${lib}/commons-beanutils-1.6.1.jar"
+ usetimestamp="true"/>
+ </target>
+
+ <target name="get-digester">
+ <get
+
src="${mavenRepo}/commons-digester/commons-digester/1.4.1/commons-digester-1.4.1.jar"
+ dest="${lib}/commons-digester-1.4.1.jar"
+ usetimestamp="true"/>
+ </target>
+
+ <target name="get-math">
+ <get
+ src="${mavenRepo}/commons-math/commons-math/1.1/commons-math-1.1.jar"
+ dest="${lib}/commons-math-1.1.jar"
+ usetimestamp="true"/>
+ </target>
+
+ <target name="get-pool">
+ <get
+ src="${mavenRepo}/commons-pool/commons-pool/1.3/commons-pool-1.3.jar"
+ dest="${lib}/commons-pool-1.3.jar"
+ usetimestamp="true"/>
+ </target>
+
+ <target name="get-logging">
+ <get
+
src="${mavenRepo}/commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar"
+ dest="${lib}/commons-logging-1.0.4.jar"
+ usetimestamp="true"/>
+ </target>
+
+ <target name="get-deps"
+
depends="get-collections,get-beanutils,get-digester,get-math,get-logging,get-pool">
+ </target>
+
+ <target name="compile" depends="clean,init,get-deps">
+ <javac srcdir="${src}/java"
+ destdir="${build}">
+ <classpath refid="compile.classpath"/>
+ <compilerarg value="-Xlint:unchecked" />
+ </javac>
+ <copy file="${basedir}/config-pool.xml" tofile="${build}/config-pool.xml"/>
+ <copy file="${basedir}/logging.properties"
tofile="${build}/logging.properties"/>
+ </target>
+
+ <target name="run" depends="compile">
+ <java classname="org.apache.commons.performance.pool.PoolTest" fork="true">
+ <classpath refid="run.classpath"/>
+ <jvmarg
+
value="-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger"/>
+ <jvmarg value="-Djava.util.logging.config.file=logging.properties"/>
+ </java>
+ </target>
+
+ <target name="clean">
+ <delete dir="${build}"/>
+ </target>
+</project>
Added: jakarta/commons/sandbox/performance/trunk/config-pool.xml
URL:
http://svn.apache.org/viewvc/jakarta/commons/sandbox/performance/trunk/config-pool.xml?view=auto&rev=558593
==============================================================================
--- jakarta/commons/sandbox/performance/trunk/config-pool.xml (added)
+++ jakarta/commons/sandbox/performance/trunk/config-pool.xml Sun Jul 22
20:21:37 2007
@@ -0,0 +1,74 @@
+<!--
+/*
+ * 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.
+ */
+ -->
+
+<configuration>
+
+ <factory>
+ <activate-latency>0</activate-latency>
+ <destroy-latency>0</destroy-latency>
+ <make-latency>100</make-latency>
+ <passivate-latency>0</passivate-latency>
+ <validate-latency>100</validate-latency>
+ <waiter-latency>0</waiter-latency>
+ </factory>
+
+ <pool>
+ <!-- GenericObjectPool or AbandonedObjectPool -->
+ <type>GenericObjectPool</type>
+ <max-active>15</max-active>
+ <max-idle>15</max-idle>
+ <min-idle>0</min-idle>
+ <max-wait>-1</max-wait>
+ <!-- block, fail, or grow -->
+ <exhausted-action>block</exhausted-action>
+ <test-on-borrow>false</test-on-borrow>
+ <test-on-return>false</test-on-return>
+ <time-between-evictions>-1</time-between-evictions>
+ <tests-per-eviction>3</tests-per-eviction>
+ <idle-timeout>-1</idle-timeout>
+ <test-while-idle>false</test-while-idle>
+ </pool>
+
+ <!-- Ignored unless pool type is AbandonedObjectPool -->
+ <abandoned-config>
+ <log-abandoned>true</log-abandoned>
+ <remove-abandoned>true</remove-abandoned>
+ <abandoned-timeout>50000</abandoned-timeout>
+ </abandoned-config>
+
+ <run>
+ <!-- integerIndexed, integerScan, or textScan -->
+ <query-type>integerIndexed</query-type>
+ <iterations>1000</iterations>
+ <clients>50</clients>
+ <delay-min>250</delay-min>
+ <delay-max>500</delay-max>
+ <delay-sigma>50</delay-sigma>
+ <!-- constant, gaussian, or poisson -->
+ <delay-type>gaussian</delay-type>
+ <!-- none, linear, random -->
+ <ramp-type>random</ramp-type>
+ <period>20000</period>
+ <!-- none, oscillating (others?)-->
+ <cycle-type>oscillating</cycle-type>
+ </run>
+
+</configuration>
Added:
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java?view=auto&rev=558593
==============================================================================
---
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
(added)
+++
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolClientThread.java
Sun Jul 22 20:21:37 2007
@@ -0,0 +1,72 @@
+/*
+ * 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.List;
+import java.util.logging.Logger;
+
+import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.math.stat.descriptive.SummaryStatistics;
+import org.apache.commons.performance.ClientThread;
+
+/**
+ * Client thread that borrows and returns objects from a pool in a loop.
+ See ClientThread javadoc for a description
+ * of how times between requests are computed.
+ *
+ */
+public class PoolClientThread extends ClientThread {
+
+ private ObjectPool pool;
+
+ /**
+ * Create a pool client thread.
+ *
+ * @param iterations number of iterations
+ * @param minDelay minumum mean time between client requests
+ * @param maxDelay minumum mean time between client requests
+ * @param delayType distribution of time between client requests
+ * @param period period of cycle for cyclic load
+ * @param cycleType type of cycle for mean delay
+ * @param logger common logger shared by all clients
+ * @param statsList List of SummaryStatistics to add results to
+ */
+ public PoolClientThread(long iterations, long minDelay, long maxDelay,
+ double sigma, String delayType, long period,
+ String cycleType, String rampType, Logger logger,
+ List <SummaryStatistics> statsList, ObjectPool pool) {
+
+ super(iterations, minDelay, maxDelay, sigma, delayType, period,
cycleType,
+ rampType, logger, statsList);
+ this.pool = pool;
+ }
+
+ /** put a few instances into the pool to start */
+ protected void init() throws Exception {
+ for (int i = 0; i < 10; i++) {
+ pool.addObject();
+ }
+ }
+ /** Borrow and return */
+ public void execute() throws Exception {
+ Waiter waiter = (Waiter) pool.borrowObject();
+ waiter.doWait();
+ pool.returnObject(waiter);
+ }
+
+}
Added:
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java?view=auto&rev=558593
==============================================================================
---
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
(added)
+++
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolSoak.java
Sun Jul 22 20:21:37 2007
@@ -0,0 +1,307 @@
+/*
+ * 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 org.apache.commons.performance.ConfigurationException;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Logger;
+
+import javax.sql.DataSource;
+
+import org.apache.commons.dbcp.AbandonedConfig;
+import org.apache.commons.dbcp.AbandonedObjectPool;
+import org.apache.commons.dbcp.ConnectionFactory;
+import org.apache.commons.dbcp.DataSourceConnectionFactory;
+import org.apache.commons.dbcp.DriverConnectionFactory;
+import org.apache.commons.dbcp.DriverManagerConnectionFactory;
+import org.apache.commons.dbcp.PoolableConnectionFactory;
+import org.apache.commons.dbcp.PoolingDataSource;
+import org.apache.commons.digester.Digester;
+import org.apache.commons.pool.KeyedObjectPoolFactory;
+import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool.impl.GenericKeyedObjectPool;
+import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory;
+import org.apache.commons.pool.impl.GenericObjectPool;
+import org.apache.commons.math.random.RandomData;
+import org.apache.commons.math.random.RandomDataImpl;
+import org.apache.commons.math.stat.descriptive.SummaryStatistics;
+import org.apache.commons.math.stat.descriptive.SummaryStatisticsImpl;
+
+/**
+ * Configurable load / performance tester for commons pool.
+ * Uses Commons Digester to parse and load configuration and spawns
+ * PoolClientThread instances to generate load and gather statistics.
+ *
+ */
+public class PoolSoak {
+ private static Logger logger = Logger.getLogger(PoolSoak.class.getName());
+ private static List <SummaryStatistics> statsList =
+ new ArrayList <SummaryStatistics>();
+
+ // Pool properties
+ private String poolType;
+ private GenericObjectPool pool;
+ private long numClients;
+ private long iterations;
+ private int maxActive;
+ private int maxIdle;
+ private int minIdle;
+ private long maxWait;
+ private byte exhaustedAction;
+ private boolean testOnBorrow;
+ private boolean testOnReturn;
+ private long timeBetweenEvictions;
+ private int testsPerEviction;
+ private long idleTimeout;
+ private boolean testWhileIdle;
+ private AbandonedConfig abandonedConfig = new AbandonedConfig();
+
+ // Client thread properties
+ private long minDelay;
+ private long maxDelay;
+ private double sigma;
+ private String delayType;
+ private String rampType;
+ private long period;
+ private String cycleType;
+
+ // WaiterFactory properties
+ private long activateLatency;
+ private long destroyLatency;
+ private long makeLatency;
+ private long passivateLatency;
+ private long validateLatency;
+ private long waiterLatency;
+
+
+ public void execute() throws Exception {
+
+ // Create object pool
+ if (poolType.equals("GenericObjectPool")) {
+ pool = new GenericObjectPool(
+ null, maxActive, exhaustedAction,
+ maxWait, maxIdle, minIdle, testOnBorrow, testOnReturn,
+ timeBetweenEvictions, testsPerEviction, idleTimeout,
+ testWhileIdle);
+ } else if (poolType.equals("AbandonedObjectPool")) {
+ pool = new AbandonedObjectPool(null,abandonedConfig);
+ } else {
+ throw new ConfigurationException(
+ "invalid pool type configuration: " + poolType);
+ }
+
+ // Create factory
+ pool.setFactory(new WaiterFactory(activateLatency, destroyLatency,
+ makeLatency, passivateLatency, validateLatency,
waiterLatency));
+
+ logger.info("Starting");
+
+ // Spawn and execute client threads
+ ExecutorService ex =
Executors.newFixedThreadPool((int)numClients);
+ for (int i = 0; i < numClients; i++) {
+ ex.execute(new PoolClientThread(iterations, minDelay,
maxDelay,
+ sigma, delayType, period, cycleType, rampType,
+ logger, statsList, pool));
+ }
+ ex.shutdown();
+ // hard time limit of one day for now
+ // TODO: make this configurable
+ ex.awaitTermination(60 * 60 * 24, TimeUnit.SECONDS);
+
+ // Compute summary statistics
+ SummaryStatistics meanSummary = new SummaryStatisticsImpl();
+ SummaryStatistics stdSummary = new SummaryStatisticsImpl();
+ SummaryStatistics minSummary = new SummaryStatisticsImpl();
+ SummaryStatistics maxSummary = new SummaryStatisticsImpl();
+ for (int i = 0; i < statsList.size(); i++) {
+ SummaryStatistics stats = (SummaryStatistics) statsList.get(i);
+ meanSummary.addValue(stats.getMean());
+ stdSummary.addValue(stats.getStandardDeviation());
+ minSummary.addValue(stats.getMin());
+ maxSummary.addValue(stats.getMax());
+ }
+ logger.info("Overall statistics for the mean");
+ logger.info(meanSummary.toString());
+ logger.info("Overall statistics for the standard deviation");
+ logger.info(stdSummary.toString());
+ logger.info("Overall statistics for the min");
+ logger.info(minSummary.toString());
+ logger.info("Overall statistics for the max");
+ logger.info(maxSummary.toString());
+ }
+
+ public void configureFactory(String activateLatency, String destroyLatency,
+ String makeLatency, String passivateLatency, String
validateLatency,
+ String waiterLatency) {
+
+ this.activateLatency = Long.parseLong(activateLatency);
+ this.destroyLatency = Long.parseLong(destroyLatency);
+ this.makeLatency = Long.parseLong(makeLatency);
+ this.passivateLatency = Long.parseLong(passivateLatency);
+ this.validateLatency = Long.parseLong(validateLatency);
+ this.waiterLatency = Long.parseLong(waiterLatency);
+ }
+
+ public void configurePool(String maxActive, String maxIdle, String minIdle,
+ String maxWait, String exhaustedAction, String testOnBorrow,
+ String testOnReturn, String timeBetweenEvictions,
+ String testsPerEviction, String idleTimeout,
+ String testWhileIdle, String type) throws ConfigurationException {
+ this.maxActive = Integer.parseInt(maxActive);
+ this.maxIdle = Integer.parseInt(maxIdle);
+ this.maxWait = Long.parseLong(maxWait);
+ this.testOnBorrow = Boolean.parseBoolean(testOnBorrow);
+ this.testOnReturn = Boolean.parseBoolean(testOnReturn);
+ this.timeBetweenEvictions = Long.parseLong(timeBetweenEvictions);
+ this.testsPerEviction = Integer.parseInt(testsPerEviction);
+ this.idleTimeout = Long.parseLong(idleTimeout);
+ this.testWhileIdle = Boolean.parseBoolean(testWhileIdle);
+ this.poolType = type;
+ if (exhaustedAction.equals("block")) {
+ this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
+ } else if (exhaustedAction.equals("fail")) {
+ this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
+ } else if (exhaustedAction.equals("grow")) {
+ this.exhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
+ } else {
+ throw new ConfigurationException(
+ "Bad configuration setting for exhausted action: "
+ + exhaustedAction);
+ }
+ }
+
+ public void configureAbandonedConfig(String logAbandoned,
+ String removeAbandoned, String abandonedTimeout) {
+ abandonedConfig.setLogAbandoned(Boolean.parseBoolean(logAbandoned));
+ abandonedConfig.setRemoveAbandoned(
+ Boolean.parseBoolean(removeAbandoned));
+ abandonedConfig.setRemoveAbandonedTimeout(
+ Integer.parseInt(abandonedTimeout));
+ }
+
+ public void configureRun(String queryType, String iterations,
+ String clients, String minDelay, String maxDelay, String sigma,
+ String delayType, String rampType, String period, String
cycleType)
+ throws ConfigurationException {
+
+ this.iterations = Long.parseLong(iterations);
+ this.numClients = Long.parseLong(clients);
+ this.minDelay = Long.parseLong(minDelay);
+ this.maxDelay = Long.parseLong(maxDelay);
+ this.sigma = Double.parseDouble(sigma);
+ this.delayType = delayType;
+ this.rampType = rampType;
+ this.period = Long.parseLong(period);
+ this.cycleType = cycleType;
+ if (cycleType.equals("oscillating") && this.period <= 0) {
+ throw new ConfigurationException(
+ "Period must be positive for oscillating cycle type");
+ }
+ }
+
+ public void configure() throws Exception {
+ Digester digester = new Digester();
+ digester.push(this);
+
+ digester.addCallMethod("configuration/factory",
+ "configureFactory", 6);
+ digester.addCallParam(
+ "configuration/factory/activate-latency", 0);
+ digester.addCallParam(
+ "configuration/factory/destroy-latency", 1);
+ digester.addCallParam(
+ "configuration/factory/make-latency", 2);
+ digester.addCallParam(
+ "configuration/factory/passivate-latency", 3);
+ digester.addCallParam(
+ "configuration/factory/validate-latency", 4);
+ digester.addCallParam(
+ "configuration/factory/waiter-latency", 5);
+
+ digester.addCallMethod("configuration/pool",
+ "configurePool", 12);
+ digester.addCallParam(
+ "configuration/pool/max-active", 0);
+ digester.addCallParam(
+ "configuration/pool/max-idle", 1);
+ digester.addCallParam(
+ "configuration/pool/min-idle", 2);
+ digester.addCallParam(
+ "configuration/pool/max-wait", 3);
+ digester.addCallParam(
+ "configuration/pool/exhausted-action", 4);
+ digester.addCallParam(
+ "configuration/pool/test-on-borrow", 5);
+ digester.addCallParam(
+ "configuration/pool/test-on-return", 6);
+ digester.addCallParam(
+ "configuration/pool/time-between-evictions", 7);
+ digester.addCallParam(
+ "configuration/pool/tests-per-eviction", 8);
+ digester.addCallParam(
+ "configuration/pool/idle-timeout", 9);
+ digester.addCallParam(
+ "configuration/pool/test-while-idle", 10);
+ digester.addCallParam(
+ "configuration/pool/type", 11);
+
+ digester.addCallMethod("configuration/run",
+ "configureRun", 10);
+ digester.addCallParam(
+ "configuration/run/query-type", 0);
+ digester.addCallParam(
+ "configuration/run/iterations", 1);
+ digester.addCallParam(
+ "configuration/run/clients", 2);
+ digester.addCallParam(
+ "configuration/run/delay-min", 3);
+ digester.addCallParam(
+ "configuration/run/delay-max", 4);
+ digester.addCallParam(
+ "configuration/run/delay-sigma", 5);
+ digester.addCallParam(
+ "configuration/run/delay-type", 6);
+ digester.addCallParam(
+ "configuration/run/ramp-type", 7);
+ digester.addCallParam(
+ "configuration/run/period", 8);
+ digester.addCallParam(
+ "configuration/run/cycle-type", 9);
+
+ digester.addCallMethod("configuration/abandoned-config",
+ "configureAbandonedConfig", 3);
+ digester.addCallParam(
+ "configuration/abandoned-config/log-abandoned", 0);
+ digester.addCallParam(
+ "configuration/abandoned-config/remove-abandoned", 1);
+ digester.addCallParam(
+ "configuration/abandoned-config/abandoned-timeout", 2);
+
+ digester.parse("config-pool.xml");
+
+ }
+}
Added:
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolTest.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolTest.java?view=auto&rev=558593
==============================================================================
---
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolTest.java
(added)
+++
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/PoolTest.java
Sun Jul 22 20:21:37 2007
@@ -0,0 +1,33 @@
+/*
+ * 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;
+
+/**
+ * Load / performance test runner.
+ *
+ */
+public class PoolTest {
+ public static void main(String[] args) {
+ PoolSoak soaker = new PoolSoak();
+ try {
+ soaker.configure();
+ soaker.execute();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+}
Added:
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/Waiter.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/Waiter.java?view=auto&rev=558593
==============================================================================
---
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/Waiter.java
(added)
+++
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/Waiter.java
Sun Jul 22 20:21:37 2007
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+/**
+ * Object created by WaiterFactory. Maintains active / valid state.
+ *
+ */
+public class Waiter {
+ private boolean active = false;
+ private boolean valid = true;
+ long latency = 0;
+
+ public Waiter(boolean active, boolean valid, long latency) {
+ this.active = active;
+ this.valid = valid;
+ this.latency = latency;
+ }
+
+ public void doWait() {
+ try {
+ Thread.sleep(latency);
+ } catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+ public long getLatency() {
+ return latency;
+ }
+
+ public void setLatency(long latency) {
+ this.latency = latency;
+ }
+
+ public boolean isValid() {
+ return valid;
+ }
+
+ public void setValid(boolean valid) {
+ this.valid = valid;
+ }
+}
Added:
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java?view=auto&rev=558593
==============================================================================
---
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java
(added)
+++
jakarta/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/pool/WaiterFactory.java
Sun Jul 22 20:21:37 2007
@@ -0,0 +1,79 @@
+/*
+ * 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 org.apache.commons.pool.PoolableObjectFactory;
+
+/**
+ * Object factory with configurable latencies for object lifecycle methods.
+ *
+ */
+public class WaiterFactory implements PoolableObjectFactory {
+
+ // TODO: implement protected getters so these can be stochastic
+ private long activateLatency = 0;
+ private long destroyLatency = 0;
+ private long makeLatency = 0;
+ private long passivateLatency = 0;
+ private long validateLatency = 0;
+ private long waiterLatency = 0;
+
+ public WaiterFactory(long activateLatency, long destroyLatency,
+ long makeLatency, long passivateLatency, long validateLatency,
+ long waiterLatency) {
+ this.activateLatency = activateLatency;
+ this.destroyLatency = destroyLatency;
+ this.makeLatency = makeLatency;
+ this.passivateLatency = passivateLatency;
+ this.validateLatency = validateLatency;
+ this.waiterLatency = waiterLatency;
+ }
+
+ public void activateObject(Object arg0) throws Exception {
+ doWait(activateLatency);
+ }
+
+ public void destroyObject(Object arg0) throws Exception {
+ doWait(destroyLatency);
+ ((Waiter) arg0).setValid(false);
+ }
+
+ public Object makeObject() throws Exception {
+ doWait(makeLatency);
+ return new Waiter(false, true, waiterLatency);
+ }
+
+ public void passivateObject(Object arg0) throws Exception {
+ ((Waiter) arg0).setActive(false);
+ doWait(passivateLatency);
+ }
+
+ public boolean validateObject(Object arg0) {
+ doWait(validateLatency);
+ return ((Waiter) arg0).isValid();
+ }
+
+ protected void doWait(long latency) {
+ try {
+ Thread.sleep(latency);
+ } catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]