Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
Initial commit of simple nexus perf library
Browse files Browse the repository at this point in the history
  • Loading branch information
peterlynch committed Nov 22, 2013
1 parent 42bf2a1 commit 9aef541
Show file tree
Hide file tree
Showing 41 changed files with 2,534 additions and 3 deletions.
71 changes: 68 additions & 3 deletions README.md
@@ -1,4 +1,69 @@
nexus-perf
==========
<!--
Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
-->
## Nexus Performance Testing Library

A Sonatype Nexus quick & dirty performance regression and stress test library.

### Building

mvn clean install

This creates an uber jar in target which contains all the needed dependencies.

For certain dependencies to be resolved and code to be buildable ( ie. nexus pro features ) you need access to the
following Sonatype repository using your Sonatype Customer Credentials

https://repository.sonatype.org/content/groups/private-nexus-dev/

See https://support.sonatype.com/entries/21582466-How-can-I-write-a-custom-staging-rule- for more info

### How it works

Using the details in the scenario xml file, the program spins up request threads for nexus. During the scenario run,
metrics are captured. At scenario end, metrics are stored in a local h2 database. If asked, the program will compare
these new metrics with a previous run, and fail if the metrics are outside a threshold.

You can only tell this library:

- where you nexus lives
- what URLs to access
- authentication to use
- number of simulated clients
- rate of requests

### Creating Scenarios

Scenarios are defined using xml files in the scenarios directory. Use existing scenarios as an example or review
the code.

### Adding Scenario Data

CSV and standard NCSA log files ( tar/gzipped ) can be parsed to simulate actual requests.

### Configuring your Nexus Under Test

Setting up Nexus is up to you! This library does not aim to help you with that.

### Running

To run test scenario and record performance metrics in db
(obviously, use actual baseline version).

./runtest.sh sample-scenario 2.4.0-09

To run test scenario, record performance metrics and the db
and compare performance to an earlier scenario run

./runtest.sh sample-scenario 2.5.0-03 2.4.0-09

To run test scenario, compare performance to an earlier scenario run,
do not record metrics in the db. Useful to test scenario itself

./runtest.sh sample-scenario - 2.4.0-09

Nexus Performance Testing Library
Binary file added data/internal-deploy.csv.gz
Binary file not shown.
Binary file added data/maven-3.1-build-artifact-access.log.gz
Binary file not shown.
Binary file added h2-1.3.173.jar
Binary file not shown.
12 changes: 12 additions & 0 deletions h2-shell.sh
@@ -0,0 +1,12 @@
#!/bin/sh
#
# Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
#
# This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
# which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
#

# open the h2 database
# Useful query:
# select * from executions;
java -cp h2*.jar org.h2.tools.Shell -url jdbc:h2:~/nexusperftest $1 $2 $3
139 changes: 139 additions & 0 deletions pom.xml
@@ -0,0 +1,139 @@
<!--
Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.sonatype.buildsupport</groupId>
<artifactId>public-parent</artifactId>
<version>5</version>
</parent>

<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus-perf</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<licenses>
<license>
<name>Eclipse Public License</name>
<url>http://www.eclipse.org/legal/epl-v10.html</url>
</license>
</licenses>

<properties>
<nexus-test-support.version>2.5.0-04</nexus-test-support.version>
<nexus-staging-client.version>2.3.4</nexus-staging-client.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.5</version>
</dependency>
<dependency>
<groupId>de.pdark</groupId>
<artifactId>decentxml</artifactId>
<version>1.4</version>
</dependency>

<dependency>
<groupId>com.sonatype.nexus.staging</groupId>
<artifactId>nexus-staging-client</artifactId>
<version>${nexus-staging-client.version}</version>
<exclusions>
<exclusion>
<artifactId>junit-dep</artifactId>
<groupId>junit</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.sonatype.nexus.client</groupId>
<artifactId>nexus-client-core</artifactId>
<version>2.5.1-01</version>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.172</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>

<dependency>
<groupId>com.sonatype.nexus.pluginkit</groupId>
<artifactId>nexus-testsuite-support</artifactId>
<version>1.3.3</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<version>4.1.4</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>2.5</version>
<configuration>
<header>header-eplv1.txt</header>
<!-- fixed in parent v6 -->
<includes combine.children="append">
<include>**/*.sh</include>
</includes>
<properties>
<year>2013</year>
</properties>
</configuration>
</plugin>
</plugins>
</build>

</project>
41 changes: 41 additions & 0 deletions prime.sh
@@ -0,0 +1,41 @@
#!/bin/bash
#
# Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
#
# This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
# which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
#


scenario=$1
buildid=$2
baselineid=$3

NEXUS_URL=http://localhost:8081/nexus
NEXUS_USERNAME=admin
NEXUS_PASSWORD=admin123

# scenario is performance/stress test scenario to execute (json file in scenarios/)
# buildid is fully qualified version of the nexus instance running at $NEXUS_URL,
# if provided enables recording of performance metris in the database
# special '-' value disables performance metrics recording
# baselineid is baseline buildid, if provided, performance of this build will be
# asserted to be within tolerance range compared to the baseline.

extra_vmargs=

if [ -n "$buildid" ]; then
extra_vmargs="$extra_vmargs -Dperftest.buildId=$buildid"

if [ -n "$baselineid" ]; then
extra_vmargs="$extra_vmargs -Dperftest.baselineId=$baselineid"
fi
fi

java -cp target/nexus-perftest-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
-Ddata.file="data/internal-deploy.csv.gz" -Ddata.format=csv
-Dnexus.baseurl=$NEXUS_URL \
-Dnexus.username=$NEXUS_USERNAME -Dnexus.password=$NEXUS_PASSWORD \
$extra_vmargs \
com.sonatype.nexus.perftest.tests.PrimeNexusRepoMain \
scenarios/$scenario.xml
46 changes: 46 additions & 0 deletions runtest.sh
@@ -0,0 +1,46 @@
#!/bin/bash
#
# Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
#
# This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
# which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
#


scenario=$1
buildid=$2
baselineid=$3

NEXUS_URL=http://localhost:8081/nexus
NEXUS_USERNAME=admin
NEXUS_PASSWORD=admin123

# scenario is performance/stress test scenario to execute (json file in scenarios/)
# buildid is fully qualified version of the nexus instance running at $NEXUS_URL,
# if provided enables recording of performance metris in the database
# special '-' value disables performance metrics recording
# baselineid is baseline buildid, if provided, performance of this build will be
# asserted to be within tolerance range compared to the baseline.


extra_vmargs=

if [ -n "$buildid" ]; then
extra_vmargs="$extra_vmargs -Dperftest.buildId=$buildid"

if [ -n "$baselineid" ]; then
extra_vmargs="$extra_vmargs -Dperftest.baselineId=$baselineid"
fi
fi

timestamp=$(date '+%Y%m%d-%H%M%S')

mkdir logs

java -cp target/nexus-perftest-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
-Dnexus.baseurl=$NEXUS_URL \
-Dnexus.username=$NEXUS_USERNAME -Dnexus.password=$NEXUS_PASSWORD \
-Dperftest.http.timeout=300000 \
$extra_vmargs \
com.sonatype.nexus.perftest.PerformanceTestRunner \
scenarios/$scenario.xml 2>&1 | tee logs/$scenario-$buildid-$timestamp.log
41 changes: 41 additions & 0 deletions scenarios/sample-download.xml
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
-->
<scenario>
<name>sample-download</name>
<duration>15 MINUTES</duration>
<swarms>
<swarm>
<name>download-large</name>
<numberOfClients>250</numberOfClients>
<rate>5/SECOND</rate>
<operation>
<class>com.sonatype.nexus.perftest.maven.DownloadOperation</class>
<repo>public</repo>
<paths>
<class>com.sonatype.nexus.perftest.maven.CsvLogParser</class>
<logfile>data/internal-deploy.csv.gz</logfile>
</paths>
</operation>
</swarm>
<swarm>
<name>download-small</name>
<numberOfClients>250</numberOfClients>
<rate>5/SECOND</rate>
<operation>
<class>com.sonatype.nexus.perftest.maven.DownloadOperation</class>
<repo>public</repo>
<paths>
<class>com.sonatype.nexus.perftest.maven.HttpdLogParser</class>
<logfile>data/maven-3.1-build-artifact-access.log.gz</logfile>
</paths>
</operation>
</swarm>
</swarms>
</scenario>

0 comments on commit 9aef541

Please sign in to comment.