To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit 1f35c628 authored by rgarner's avatar rgarner
Browse files

[svn r441] Basic tomcat benchmark:

 - Starts tomcat on port 7080
 - Creates a number of client threads, which work through the tomcat examples
   application.
 - Deletes the jsp cache between iterations so as to capture the jsp compilation
parent b3685138
<project name="tomcat" default="all" basedir="../..">
<description>DaCapo Tomcat benchmark</description>
<property file="dacapo.properties"/>
<property name="bm-name" value="tomcat"/>
<property name="bm-version" value="6.0.18"/>
<property name="bm-url" value="${apache.dl.url}/${bm-name}/${bm-name}-6/v6.0.18/src"/>
<property name="bm-src" value="apache-${bm-name}-${bm-version}-src.tar.gz"/>
<target name="build-properties">
<property name="bm-build-top" value="${bm-build-dir}/apache-${bm-name}-${bm-version}-src"/>
</target>
<import file="../common.xml"/>
<target name="unpack" depends="untar"/>
<target name="bm-build" depends="build-properties,commons-httpclient">
<ant antfile="build.xml" inheritall="false" dir="${bm-build-top}">
<property name="base.path" value="${bm-downloads}"/>
<target name="download"/>
<target name="deploy"/>
</ant>
<ant antfile="dist.xml" inheritall="false" dir="${bm-build-top}">
<property name="base.path" value="${bm-downloads}"/>
<target name="dist-static"/>
</ant>
<javac srcdir="${bm-src-dir}" destdir="${bm-output-dir}"
source="1.5" target="1.5"
includes="org/dacapo/tomcat/*"
debug="true" debuglevel="lines,vars,source">
<classpath>
<pathelement path="${harness-classpath}"/>
<pathelement path="${commons-httpclient-jar}"/>
<fileset dir="${bm-build-top}/output/dist/lib">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${bm-build-top}/output/dist/bin">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<target name="bm-data" depends="bm-build,build-properties">
<copy todir="${bm-build-top}/output/dist/conf"
file="${bm-files}/server.xml"
overwrite="true">
<fileset file="${bm-files}/server.xml"/>
<fileset file="${bm-files}/tomcat-users.xml"/>
</copy>
<zip destfile="${bm-dat}/tomcat.zip">
<fileset dir="${bm-build-top}/output/dist"/>
<fileset file="${bm-files}/catalina.properties"/>
</zip>
</target>
<target name="jar" depends="bm-data,build-properties">
<copy todir="${bm-jars}">
<fileset dir="${bm-build-top}/output/dist/bin" includes="*.jar"/>
<fileset file="${commons-httpclient-jar}"/>
<fileset file="${commons-logging-jar}"/>
<fileset file="${commons-codec-jar}"/>
</copy>
<jar destfile="${bm-jars}/dacapo-tomcat.jar">
<fileset dir="${bm-output-dir}" includes="**/*.class"/>
</jar>
</target>
</project>
\ No newline at end of file
# 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.
#
# List of comma-separated packages that start with or equal this string
# will cause a security exception to be thrown when
# passed to checkPackageAccess unless the
# corresponding RuntimePermission ("accessClassInPackage."+package) has
# been granted.
package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.,sun.beans.
#
# List of comma-separated packages that start with or equal this string
# will cause a security exception to be thrown when
# passed to checkPackageDefinition unless the
# corresponding RuntimePermission ("defineClassInPackage."+package) has
# been granted.
#
# by default, no packages are restricted for definition, and none of
# the class loaders supplied with the JDK call checkPackageDefinition.
#
package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.
#
#
# List of comma-separated paths defining the contents of the "common"
# classloader. Prefixes should be used to define what is the repository type.
# Path may be relative to the CATALINA_HOME or CATALINA_BASE path or absolute.
# If left as blank,the JVM system loader will be used as Catalina's "common"
# loader.
# Examples:
# "foo": Add this folder as a class repository
# "foo/*.jar": Add all the JARs of the specified folder as class
# repositories
# "foo/bar.jar": Add bar.jar as a class repository
common.loader=${catalina.home}/lib/*.jar,${catalina.home}/bin/*.jar
#
# List of comma-separated paths defining the contents of the "server"
# classloader. Prefixes should be used to define what is the repository type.
# Path may be relative to the CATALINA_HOME or CATALINA_BASE path or absolute.
# If left as blank, the "common" loader will be used as Catalina's "server"
# loader.
# Examples:
# "foo": Add this folder as a class repository
# "foo/*.jar": Add all the JARs of the specified folder as class
# repositories
# "foo/bar.jar": Add bar.jar as a class repository
server.loader=
#
# List of comma-separated paths defining the contents of the "shared"
# classloader. Prefixes should be used to define what is the repository type.
# Path may be relative to the CATALINA_BASE path or absolute. If left as blank,
# the "common" loader will be used as Catalina's "shared" loader.
# Examples:
# "foo": Add this folder as a class repository
# "foo/*.jar": Add all the JARs of the specified folder as class
# repositories
# "foo/bar.jar": Add bar.jar as a class repository
# Please note that for single jars, e.g. bar.jar, you need the URL form
# starting with file:.
shared.loader=
#
# String cache configuration.
tomcat.util.buf.StringCache.byte.enabled=true
#tomcat.util.buf.StringCache.char.enabled=true
#tomcat.util.buf.StringCache.trainThreshold=500000
#tomcat.util.buf.StringCache.cacheSize=5000
9bdbb1c1d79302c80057a70b18fe6721 apache-tomcat-6.0.18-src.tar.gz
<?xml version='1.0' encoding='utf-8'?>
<!--
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.
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="7005" shutdown="SHUTDOWN">
<!--APR library loader. Documentation at /docs/apr.html -->
<!-- <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> -->
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="7080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="7443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="7080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="7443" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<!--
<Connector port="7443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="7009" protocol="AJP/1.3" redirectPort="7443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- The request dumper valve dumps useful debugging information about
the request and response data received and sent by Tomcat.
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.valves.RequestDumperValve"/>
-->
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false"
xmlValidation="false" xmlNamespaceAware="false">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
-->
</Host>
</Engine>
</Service>
</Server>
package org.dacapo.harness;
import java.io.File;
import java.lang.reflect.Constructor;
import org.dacapo.harness.Benchmark;
import org.dacapo.parser.Config;
/**
* Benchmark harness for the Tomcat benchmark
*
* @author Robin Garner
* @date $Date: 2008-07-27 12:53:06 +1000 (Sun, 27 Jul 2008) $
* @id $Id: $
*
*/
public class Tomcat extends Benchmark {
private final Class<?> clazz;
private final Constructor<Runnable> clientConstructor;
private final Object controller;
@SuppressWarnings("unchecked")
public Tomcat(Config config, File scratch) throws Exception {
super(config,scratch);
this.clazz = Class.forName("org.dacapo.tomcat.Control", true, loader);
this.method = clazz.getMethod("exec",String.class);
/* Create a constructor for the tomcat controller */
Constructor<?> controlConstructor = clazz.getConstructor(File.class,ClassLoader.class,int.class);
this.controller = controlConstructor.newInstance(scratch,loader,7080);
/* Create a constructor for the tomcat client */
Class<Runnable> clientClass = (Class<Runnable>)Class.forName("org.dacapo.tomcat.Client", true, loader);
this.clientConstructor = clientClass.getConstructor(
File.class, int.class, int.class, boolean.class);
}
/**
* One-off setup
*/
@Override
public void prepare(String size) throws Exception {
super.prepare(size);
try {
useBenchmarkClassLoader();
try {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "info");
System.setProperty("catalina.home", scratch.getAbsolutePath());
System.setProperty("catalina.config", new File(fileInScratch("catalina.properties")).toURL().toExternalForm());
method.invoke(controller,"prepare");
System.out.println("Server thread created");
// Run one iteration to get static startup costs out of the way
System.out.println("Pre-benchmark warmup");
method.invoke(controller, "startIteration");
clientConstructor.newInstance(scratch,0,1,isVerbose()).run();
method.invoke(controller, "stopIteration");
System.out.println("Pre-benchmark warmup complete");
postIterationCleanup(size);
} finally {
revertClassLoader();
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* After each iteration, delete the output files
*/
public void postIteration(String size) throws Exception {
super.postIteration(size);
}
/**
* An iteration of the benchmark - runs in the benchmark classloader
*/
public void iterate(String size) throws Exception {
System.out.println("Loading web application");
method.invoke(controller, "startIteration");
final int threadCount = getThreadCount(config,size);
String[] args = config.getArgs(size);
final int iterations = Integer.parseInt(args[0]);
/*
* In case the # iterations doesn't evenly divide among the processors,
* we ensure that some threads do one more iteration than others
*/
final int iterationsPerClient = iterations / threadCount;
final int oddIterations = iterations - (iterationsPerClient * threadCount);
final Thread[] threads = new Thread[threadCount];
System.out.println("Creating client threads");
for (int i=0; i < threadCount; i++) {
Runnable client = clientConstructor.newInstance(
scratch,
i,
iterationsPerClient + (i < oddIterations ? 1 : 0),
isVerbose());
threads[i] = new Thread(client);
threads[i].start();
}
System.out.println("Waiting for clients to complete");
for (int i=0; i < threadCount; i++) {
threads[i].join();
}
System.out.println("Client threads complete ... unloading web application");
method.invoke(controller, "stopIteration");
}
@Override
protected void postIterationCleanup(String size) {
super.postIterationCleanup(size);
/* Delete the tomcat cache */
deleteTree(new File(scratch,"work"));
}
@Override
public void cleanup() {
try {
method.invoke(controller,"cleanup");
} catch (Exception e) {
throw new RuntimeException(e);
}
System.out.println("Server stopped ... iteration complete");
super.cleanup();
}
@SuppressWarnings("unused")
private void dumpThreads() {
ThreadGroup tg = Thread.currentThread().getThreadGroup();
int nThreads = tg.activeCount();
Thread[] threads = new Thread[nThreads*2];
nThreads = Thread.enumerate(threads);
System.out.printf("==================== Dumping %d Threads: ====================%n",nThreads);
System.out.flush();
for (int i=0; i < nThreads; i++) {
if (threads[i] != null) {
System.out.print(threads[i].getName()+": ");
StackTraceElement[] stack = threads[i].getStackTrace();
for (int j=0; j < stack.length; j++) {
for (int k=0; k < j; k++) System.out.print(" ");
System.out.println(stack[j].getClassName()+"."+stack[j].getMethodName()+":"+stack[j].getLineNumber()+" <- ");
}
} else {
System.out.print("null ");
}
System.out.flush();
}
System.out.println();
System.out.flush();
System.out.printf("==================== Thread Dump End ====================%n");
}
/**
* Stub which exists <b>only</b> to facilitate whole program
* static analysis on a per-benchmark basis. See also the "split-deps"
* ant build target, which is also provided to enable whole program
* static analysis.
*/
public static void main(String args[]) throws Exception {
// create dummy harness and invoke with dummy arguments
(new Tomcat(null, null)).run(null, "");
}
}
package org.dacapo.tomcat;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.params.HttpClientParams;
public class AuthenticatedSession extends Session {
private final String username;
private final String password;
/**
* Factory method - forces correct initialization
* @param username
* @param password
* @return
*/
public static AuthenticatedSession create(String username, String password) {
AuthenticatedSession result = new AuthenticatedSession(username, password);
result.init();
return result;
}
protected AuthenticatedSession(String username, String password) {
this.username = username;
this.password = password;
}
@Override
protected void setClientState(HttpState state) {
super.setClientState(state);
Credentials defaultcreds = new UsernamePasswordCredentials(username, password);
state.setCredentials(new AuthScope("localhost", Control.port, AuthScope.ANY_REALM), defaultcreds);
}
@Override
protected void setClientParams(HttpClientParams params) {
super.setClientParams(params);
params.setAuthenticationPreemptive(true);
}
}
package org.dacapo.tomcat;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
/**
* A client of the tomcat benchmark.
*
* Each client iterates through a list of queries for a given number
* of iterations, using a single session context.
*/
public class Client implements Runnable {
private final File logDir;
private final int ordinal;
private final int pageCount;
private final boolean verbose;
private final PrintWriter log;
private final Session session = Session.create();
/**
* The pages to iterate through
*/
private final List<Page> pages = Arrays.asList(
new HttpGet(session,"/examples/jsp/jsp2/el/basic-arithmetic.jsp","396eaab04e83090b4d4b259eeca17a5990b7fd73"),
new HttpGet(session,"/examples/jsp/jsp2/el/basic-comparisons.jsp","99844226d16c12f5f41e2e8db425bee2c688eeb0"),
new HttpGet(session,"/examples/jsp/jsp2/el/implicit-objects.jsp?foo=bar","e799ace810ab35a0b56627ddd276e4ad35dbaff4"),
new HttpGet(session,"/examples/jsp/jsp2/el/functions.jsp?foo=JSP+2.0","c30b0bc98277ad4c2ce48388b3017873f9ca6c9b"),
new HttpGet(session,"/examples/jsp/jsp2/simpletag/hello.jsp","b741884a658f677c7223296c6138089043030024"),
new HttpGet(session,"/examples/jsp/jsp2/simpletag/repeat.jsp","a171bec81dbabd3ad22f4694e54c79d82c5286b9"),
new HttpGet(session,"/examples/jsp/jsp2/simpletag/book.jsp","56044c60aa6744e100033ac7ee1d7e8a11f7d803"),
new HttpGet(session,"/examples/jsp/jsp2/tagfiles/hello.jsp","5117780dcff2717856acf34424a37bea277e6d48"),
new HttpGet(session,"/examples/jsp/jsp2/tagfiles/panel.jsp","dc67adddb6a2b1f97f0d0991034a88bec8a02009"),
new HttpGet(session,"/examples/jsp/jsp2/tagfiles/products.jsp","96d0f521b94868a2450735a453de19753ce4df6e"),
// Prints the date - don't validate
new HttpGet(session,"/examples/jsp/jsp2/jspx/basic.jspx",200),
new HttpGet(session,"/examples/jsp/jsp2/jspx/svgexample.html",200,"2cc0bde1f9dcdbfdbd2a26ccd7addfce5c332a45"),
new HttpGet(session,"/examples/jsp/jsp2/jspx/textRotate.jspx?name=JSPX",200,"62d28df98503af07933c280c991d2742edc5f9f9"),
new HttpGet(session,"/examples/jsp/jsp2/jspattribute/jspattribute.jsp","deafbfc6b6d74013c8684af4ff6caf0f713fcb82"),
// Shuffle is by definition dynamic
new HttpGet(session,"/examples/jsp/jsp2/jspattribute/shuffle.jsp",200),
new HttpGet(session,"/examples/jsp/jsp2/misc/dynamicattrs.jsp","30d42a712e2d336fb6ea84e550d592a38879dde2"),
new HttpGet(session,"/examples/jsp/jsp2/misc/config.jsp","2c05579ee7982bc35add4843438b5ded8d912a9b"),
// Number guessing game
new NumGuess(session),
// Shows the current time, so can't be digested
new HttpGet(session,"/examples/jsp/dates/date.jsp"),
// Can return system-specific data
new HttpGet(session,"/examples/jsp/snp/snoop.jsp",200),
new HttpGet(session,"/examples/jsp/error/error.html",200,"7a4eee413a6d4ebc66baca65c1fcf4c2dd1e9904"),
new HttpGet(session,"/examples/jsp/error/err.jsp?name=audi&submit=Submit",500,"7f207b1e98367e0ee43056f5a242421a46d82eb9"),
new HttpGet(session,"/examples/jsp/error/err.jsp?name=integra&submit=Submit",200,"13fd4b057c42253a761c0a6499b89d314c09b2c2"),
/*
* The following group of methods form a session, adding items to a shopping cart
* and then removing them. Because each client should have a single persistent
* session across several iterations through this list, we should leave the session
* as we find it.
*/
new HttpGet(session,"/examples/jsp/sessions/carts.html",200,"3754d762eca41dc2eb001f98a4707ea38f2c5433"),
new HttpPost(session,"/examples/jsp/sessions/carts.jsp?item=NIN+CD&submit=add",200,"3f78ce05a2e8f07aa4f94f19538c28971695d86d"),
new HttpPost(