Author: psteitz
Date: Sun Nov 25 15:56:45 2007
New Revision: 598095
URL: http://svn.apache.org/viewvc?rev=598095&view=rev
Log:
Added http LoadGenerator example.
Added:
commons/sandbox/performance/trunk/build-http.xml (with props)
commons/sandbox/performance/trunk/config-http.xml (with props)
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpClientThread.java
(with props)
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpSoak.java
(with props)
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpTest.java
(with props)
Modified:
commons/sandbox/performance/trunk/pom.xml
commons/sandbox/performance/trunk/src/site/apt/index.apt
Added: commons/sandbox/performance/trunk/build-http.xml
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/build-http.xml?rev=598095&view=auto
==============================================================================
--- commons/sandbox/performance/trunk/build-http.xml (added)
+++ commons/sandbox/performance/trunk/build-http.xml Sun Nov 25 15:56:45 2007
@@ -0,0 +1,128 @@
+<!--
+/*
+ * 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="HttpTest" 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">
+ <pathelement location="${jdbc-jar}"/>
+ <pathelement location="${pool-jar}"/>
+ <pathelement location="${dbcp-jar}"/>
+ <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-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-httpclient">
+ <get
+
src="${mavenRepo}/commons-httpclient/commons-httpclient/3.0.1/commons-httpclient-3.0.1.jar"
+ dest="${lib}/commons-httpclient-3.0.1.jar"
+ usetimestamp="true"/>
+ </target>
+
+ <target name="get-codec">
+ <get
+
src="${mavenRepo}/commons-codec/commons-codec/1.3/commons-codec-1.3.jar"
+ dest="${lib}/commons-codec-1.3.jar"
+ usetimestamp="true"/>
+ </target>
+
+ <target name="get-deps"
+ depends="get-collections,get-beanutils,get-digester,get-math,get-logging,
+ get-httpclient, get-codec">
+ </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.http.HttpTest" 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"/>
+ <!-- <jvmarg value="-Xrunjmp"/> -->
+ </java>
+ </target>
+
+ <target name="clean">
+ <delete dir="${build}"/>
+ </target>
+</project>
Propchange: commons/sandbox/performance/trunk/build-http.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/performance/trunk/config-http.xml
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/config-http.xml?rev=598095&view=auto
==============================================================================
--- commons/sandbox/performance/trunk/config-http.xml (added)
+++ commons/sandbox/performance/trunk/config-http.xml Sun Nov 25 15:56:45 2007
@@ -0,0 +1,47 @@
+<!--
+/*
+ * 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>
+
+ <run>
+ <!-- integerIndexed, integerScan, or textScan -->
+ <iterations>500</iterations>
+ <clients>40</clients>
+ <delay-min>200</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>
+ <ramp-period>1000</ramp-period>
+ <peak-period>2000</peak-period>
+ <trough-period>1000</trough-period>
+ <!-- none, oscillating (others?)-->
+ <cycle-type>oscillating</cycle-type>
+ </run>
+ <http>
+ <url>http://localhost:8080/DBTest/test.jsp</url><!--GET or POST-->
+ <method>GET</method><!--Socket timeout in milliseconds-->
+ <socket-timeout>20000</socket-timeout><!--String to search for in
response-->
+ <success-key>updated</success-key></http>
+
+</configuration>
Propchange: commons/sandbox/performance/trunk/config-http.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/performance/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/pom.xml?rev=598095&r1=598094&r2=598095&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/pom.xml (original)
+++ commons/sandbox/performance/trunk/pom.xml Sun Nov 25 15:56:45 2007
@@ -69,6 +69,11 @@
<version>1.1</version>
</dependency>
<dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.0.1</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
Added:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpClientThread.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpClientThread.java?rev=598095&view=auto
==============================================================================
---
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpClientThread.java
(added)
+++
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpClientThread.java
Sun Nov 25 15:56:45 2007
@@ -0,0 +1,95 @@
+/*
+ * 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.http;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+
+import org.apache.commons.math.stat.descriptive.SummaryStatistics;
+import org.apache.commons.performance.ClientThread;
+
+/**
+ * Client thread that executes http requests in a loop against a configured
+ * url, with the number of requests, time between requests and
+ * query strings governed by constructor parameters. See
+ * [EMAIL PROTECTED] ClientThread ClientThread javadoc} for a description
+ * of how times between requests are computed.
+ *
+ */
+public class HttpClientThread extends ClientThread {
+
+ private HttpClient httpClient = new HttpClient();
+ private HttpMethod httpMethod = null;
+ private String successKey = null;
+
+ public HttpClientThread(long iterations, long minDelay, long maxDelay,
+ double sigma, String delayType, long rampPeriod,
+ long peakPeriod, long troughPeriod, String cycleType,
+ String rampType, Logger logger,
+ List <SummaryStatistics> statsList, String url, String method,
+ int socketTimeout, String successKey) {
+
+ super(iterations, minDelay, maxDelay, sigma, delayType, rampPeriod,
+ peakPeriod, troughPeriod, cycleType, rampType, logger,
+ statsList);
+
+ httpClient.getParams().setSoTimeout(socketTimeout);
+ if (method.trim().toUpperCase().equals("POST")) {
+ httpMethod = new PostMethod(url);
+ } else {
+ httpMethod = new GetMethod(url);
+ }
+ this.successKey = successKey;
+ }
+
+ /** Nothing to do here at this point */
+ public void setUp() throws Exception {}
+
+ /**
+ * Execute the http method against the target url.
+ * Throws HttpException if something other than 200 status is returned
+ * or if there is a successKey configured and the response does not contain
+ * the specified key.
+ */
+ public void execute() throws Exception {
+ int statusCode = httpClient.executeMethod(httpMethod);
+ if (statusCode != HttpStatus.SC_OK) {
+ throw new HttpException("Request failed with status code: "
+ + statusCode);
+ }
+ // Should use stream here - for now assume body is small
+ String responseBody = httpMethod.getResponseBodyAsString();
+ if (successKey != null && responseBody.indexOf(successKey) < 0 ) {
+ throw new HttpException("Response did not include success key: "
+ + successKey);
+ }
+ }
+
+ /** Release http connection */
+ public void cleanUp() throws Exception {
+ httpMethod.releaseConnection();
+ }
+
+}
Propchange:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpClientThread.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpSoak.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpSoak.java?rev=598095&view=auto
==============================================================================
---
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpSoak.java
(added)
+++
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpSoak.java
Sun Nov 25 15:56:45 2007
@@ -0,0 +1,88 @@
+/*
+ * 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.http;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.commons.math.stat.descriptive.SummaryStatistics;
+import org.apache.commons.performance.ClientThread;
+import org.apache.commons.performance.LoadGenerator;
+import org.apache.commons.performance.dbcp.DBCPClientThread;
+
+/**
+ * Simple http load / performance tester, providing another LoadGenerator
+ * example.
+ *
+ * Uses Commons Digester to parse and load configuration and spawns
+ * HTTPClientThread instances to generate load and gather statistics.
+ *
+ */
+
+public class HttpSoak extends LoadGenerator {
+
+ private String url;
+ private String method;
+ private int socketTimeout;
+ private String successKey;
+
+ /** Nothing to do here yet */
+ protected void init() throws Exception {}
+
+ protected ClientThread makeClientThread(
+ long iterations, long minDelay, long maxDelay, double sigma,
+ String delayType, long rampPeriod, long peakPeriod,
+ long troughPeriod, String cycleType, String rampType,
+ Logger logger, List <SummaryStatistics> statsList) {
+
+ return new HttpClientThread(iterations, minDelay, maxDelay,
+ sigma, delayType, rampPeriod, peakPeriod,
+ troughPeriod, cycleType, rampType, logger,
+ statsList, url, method, socketTimeout, successKey);
+ }
+
+ /**
+ * Add http client configuration to parameters loaded by super.
+ * Also set config file name.
+ */
+ protected void configure() throws Exception {
+
+ super.configure(); // loads run configuration
+
+ digester.addCallMethod("configuration/http",
+ "configureHttp", 4);
+ digester.addCallParam("configuration/http/url", 0);
+ digester.addCallParam("configuration/http/method", 1);
+ digester.addCallParam("configuration/http/socket-timeout", 2);
+ digester.addCallParam("configuration/http/success-key", 3);
+
+ this.configFile = "config-http.xml";
+ }
+
+ // ------------------------------------------------------------------------
+ // Configuration methods specific to this LoadGenerator invoked by Digester
+ // when superclass execute calls digester.parse.
+ // ------------------------------------------------------------------------
+ public void configureHttp(String url,
+ String method, String socketTimeout, String successKey) {
+ this.url = url;
+ this.method = method;
+ this.socketTimeout = Integer.parseInt(socketTimeout);
+ this.successKey = successKey;
+ }
+}
Propchange:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpSoak.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpTest.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpTest.java?rev=598095&view=auto
==============================================================================
---
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpTest.java
(added)
+++
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpTest.java
Sun Nov 25 15:56:45 2007
@@ -0,0 +1,32 @@
+/*
+ * 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.http;
+
+/**
+ * Load / performance test runner.
+ *
+ */
+public class HttpTest {
+ public static void main(String[] args) {
+ HttpSoak soaker = new HttpSoak();
+ try {
+ soaker.execute();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+}
Propchange:
commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/http/HttpTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/performance/trunk/src/site/apt/index.apt
URL:
http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/site/apt/index.apt?rev=598095&r1=598094&r2=598095&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/site/apt/index.apt (original)
+++ commons/sandbox/performance/trunk/src/site/apt/index.apt Sun Nov 25
15:56:45 2007
@@ -31,16 +31,17 @@
spawn ClientThreads and aggregate statistics across threads. Configuration
is loaded at the beginning of a run from an XML configuration file.
- Concrete implementations are provided for commons pool and commons DBCP.
+ Concrete implementations are provided for commons pool and commons DBCP. A
+ primitive http load generator is also included as another sample
LoadGenerator.
See the class javadoc for
{{{./apidocs/org/apache/commons/performance/ClientThread.html}ClientThread}}
and
{{{./apidocs/org/apache/commons/performance/LoadGenerator.html}LoadGenerator}}
for more information on how to extend these classes to develop other
- microbenchmark clients. The Pool and DBCP implementations (in the
- {{{./apidocs/org/apache/commons/performance/pool/package-summary.html}pool}}
- and
+ microbenchmark clients. The Pool, DBCP, and HTTP implementations (in the
+ {{{./apidocs/org/apache/commons/performance/pool/package-summary.html}pool}},
{{{./apidocs/org/apache/commons/performance/dbcp/package-summary.html}dbcp}}
+ {{{./apidocs/org/apache/commons/performance/http/package-summary.html}http}}
packages, respectively) provide examples of how to do this.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -48,11 +49,11 @@
~~ may break / be unnecessary
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- {{{#Compiling and running the DBCP and pool tests}Pool and DBCP tests}} |
+ {{{#Compiling and running the DBCP, pool and http tests}Pool, DBCP and http
tests}} |
{{{#Configuration}Configuration}} | {{{#Statistics}Statistics}} |
{{{#Development tasks}Development tasks}}
-{Compiling and running the DBCP and Pool tests}
+{Compiling and running the DBCP, pool and http tests}
[DBCP] To run the dbcp tests:
@@ -88,6 +89,20 @@
+--------------------
[]
+
+ [http] To run the http tests:
+
+ [[1]] Edit the configuration in config-http.xml
+
+ [[2]] Edit logging.properties to provide a real path for the log file
+
+ [[3]] Execute:
+
++--------------------
+ant -f build-http.xml
++--------------------
+
+ []
{Configuration}
@@ -194,6 +209,19 @@
|configuration/poolable-connection-factory/max-open-statements|When
pool-prepared-statements is true, this setting determines the maximum number or
pooled prepared statements that can be open at a given time|10 - at most 10
prepared statements can be open at the same time|
*-----------------------------+-------------------------------------------------+----------------------------------------+
+* Configuration for http
+
+*-----------------------------+-------------------------------------------------+----------------------------------------+
+|<<XML path to parameter>> |<<What the parameter means>> |<<Sample setting>>|
+*-----------------------------+-------------------------------------------------+----------------------------------------+
+|configuration/http/url|url of resource to test|http://localhost/index.html|
+*-----------------------------+-------------------------------------------------+----------------------------------------+
+|configuration/http/method|http method -GET or POST|GET|
+*-----------------------------+-------------------------------------------------+----------------------------------------+
+|configuration/http/socket-timeout|http socket connection timeout in
milliseconds|20000 - timeout after 20 seconds|
+*-----------------------------+-------------------------------------------------+----------------------------------------+
+|configuration/http/success-key|string to look for in http response indicating
success|'successful' - threads throw HttpException if this string is not found
in the response|
+*-----------------------------+-------------------------------------------------+----------------------------------------+
{Statistics}
@@ -212,11 +240,6 @@
[[]] Property representation and management is poor. Configuration objects
should be defined and Digester should create and populate configuration
beans.
-
- [[]] The Ant build for the dbcp and pool tests needs work. Currently to
- change the pool or dbcp implementations to use in these tests, you need
- to hack the get-deps tasks and clean the lib directory. The dbcp and pool
- jars should be configurable.
[[]] More pool types and more datasource / connection pool types should be
supported.