Summary | Admin | Home Page | Forums | Tracker | Bugs | Support | Patches | RFE | Lists | Tasks | Docs | News | CVS | Files

Table of Contents


Java Requirements

JBenchmark supports JDK1.2, 1.3, 1.4 and 5.

JBenchmark does not work with JDK1.1.

Dependencies

JBenchmark requires the following libraries:
Additional build time dependencies


Installation

Add jbenchmark and dependant jars to your project
Add jbenchmark task def to your project.

Configuration

    <target name="benchmark" description="Runs the benchmarks" depends="tasks">
        <delete file="${benchmark.log}"/>
        <property name="threads" value="5"/>
        <property name="duration" value="60"/>
        <property name="delay" value="0"/>
        <taskdef name="benchmark" classname="net.sf.jbenchmark.BenchmarkTask">
            <classpath>
                <path refid="project.class.path"/>
            </classpath>
        </taskdef>

        <benchmark>
            <script path="scripts/benchmark.all.xml"/>
            <httpserver hostname="${benchmark.host}" port="${benchmark.port}" threadSession="true"/>
            <publisher logfile="${benchmark.log}"/>
        </benchmark>
    </target>

<benchmark> Ant Task

The <benchmark> task takes the following attributes:

AttributeDescription
logfile The log file to write results to. The benchmark results are appended to this file. If not specified, the results are written to Ant's stdout.
script A benchmark script to be executed.

Nested Element

The <benchmark> task takes the following nested elements:

<script>

The <script> element defines a benchmark script to execute. It takes the following attributes:

AttributeDescription
path A benchmark script to be executed.

Logging

Script Samples

The benchmark tool is a simple HTTP benchmarking tool. Benchmarks are defined in an XML based benchmark script, and an Ant task is used to execute the script.

Sample 1 - Basic Page hits

<test>
    <!-- Hit the web page with multiple threads, for a fixed duration -->
    <web-page prefetchCount="15" prefetchDelay="500" threads="${threads}" duration="${duration}" delay="${delay}"
        path="/path/" name="index.xml">
        <assert-response-status status="200"/>
        <assert-response-size max="20000"/>
    </web-page>
</test>

Sample 2 - simulate workload.

Here is a more complex workload.
<test xmlns:jelly="jelly:core" xmlns:util="jelly:util">
    <thread-group threads="5">
        <loop-duration duration="120">
            <jelly:import uri="include/sitesearch.xml" inherit="true"/>
        </loop-duration>
        <timer name="Preload times only (get the server and caches warmed up)"/>
    </thread-group>

    <thread-group threads="${threads}">
        <loop-duration duration="${duration}">
            <jelly:import uri="include/sitesearch.xml" inherit="true"/>
        </loop-duration>
        <timer name="search times"/>
    </thread-group>

file:include/sitesearch.xml

            <choose-random>
                <!-- 80% of hits are searches with partial property name-->
                <choice weight="80">
                    <!-- 50% of searches have accomodation type set -->
                    <random var="accommType">
                        <token-list tokens=",,,1,2,3"/>
                    </random>
                    <random var="propertyName">
                        <sql-list query="select substring(DisplayName, 1, 4) from PROPERY"/>
                    </random>
                    <http-get path="/Search.jsp?propertyName={propertyName}&accomodationType={accommType}">
                        <assert-response-status status="200"/>
                        <assert-response-size min="1000" max="600000"/>
                    </http-get>
                    <timer name="searchby.propname"/>
                </choice>
                <!-- 20% of searches by region -->
                <choice weight="20">
                    <random var="regionid">
                        <sql-list query="select id from REGION"/>
                    </random>
                    <http-get path="/Search.jsp?region={regionid}">
                        <assert-response-status status="200"/>
                        <assert-response-size min="1000" max="600000"/>
                    </http-get>
                    <timer name="searchby.region"/>
                </choice>
            </choose-random>

Benchmark Script Format

A benchmark script is an XML file. The root element of the script must be a <test> test group element.

Script are interpreted as Jelly scripts, and so can include Jelly tags in addition to the tags listed below. In particular, the <import> tag can be used to import other scripts. Scripts can access Ant properties using Ant-style ${property-name} expressions.

Test Group Elements

Test group elements defines a group of tests to execute. The tests are defined as nested elements, and are executed in the order that they appear in the script.

<loop> Test Group

The <loop> element defines a test group that executes multiple times. the element takes the following attributes:

AttributeDescription
count The number of times to execute the test group.

<loop-duration> Test Group

The <loop-duration> element defines a test group that executes multiple times, for a fixed amount of time. This element takes the following attributes:

AttributeDescription
duration The amount of time (in seconds) to execute the test group.

<thread-group> Test Group

The <thread-group> element defines a test group that executes concurrently in multiple threads. Each thread executes the test group once. This element takes the following attributes:

AttributeDescription
rampup The amount of time (in seconds) to take to start the threads.
threads The number of threads to use.

<parallel> Test Group

The <parallel> element defines a test group that executes each of its tests in parallel.

Test Elements

Test elements define a single atomic test to execute. They can be added to any test group element.

<http-get> Test

The <http-get> element performs an HTTP get of a particular resource. This element takes the following attributes:

AttributeDescription
path The path of the resource to get.

The <http-get> element can include nested assertion elements.

<fixed-delay> Test

The <fixed-delay> element introduces a delay of fixed duration. This element takes the following attributes:

AttributeDescription
delay The length of the delay (in milliseconds).

Other Elements

There are a number assertion statements to attempt to catch errors with the performance run, like when pages are returning not returning 200, or an error on the page results in less work than expected being performed.

<timer> Element

The <timer> element defines a timer, which gathers timing statistics. A <timer> element can be added to a test group, and it will gather statistics for all HTTP tests in that group (including all nested tests). This element takes the following attributes:

AttributeDescription
name An identifying name for the timer. This name will appear in the log file.

<assert-duration> Element

The <assert-duration> element can be added to any test or test group element, and checks that the test execution time does not exceed an expected maximum value.

<assert-response-status> Element

The <assert-response-status> element can be added to any HTTP test, and checks that the HTTP response returns the expected status code.

<assert-response-size> Element

The <assert-response-size> element can be added to any HTTP test, and checks that the HTTP response returns a body whose size is within an expected range.

<http-server> Element

The <http-server> element can be added to any test group, and specifies the HTTP server that all HTTP tests in that group (including all nested tests) should use.

<console-publisher> Element

The <console-publisher> element can be added to any test group, and directs the output of all test timers in that group (including all nested timers) to Ant stdout.

<file-publisher> Element

The <file-publisher> element can be added to any test group, and directs the output of all test timers in that group (including all nested timers) to a log file.



SourceForge.net