Skip to content

Commit

Permalink
Create a Gatling load testing scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
tsegismont committed Jun 1, 2015
1 parent 09d7454 commit 363ba9e
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 0 deletions.
23 changes: 23 additions & 0 deletions load-tests/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
= Hawkular Metrics Load Tests
:type: article

A simple load testing tool for Hawkular Metrics

== Why a Maven project?

Because it makes it easier for developers to fire a load test:
there's no need to download, extract and configure PATH.

== The scenario

The simulation consists in sending metrics reports from a configurable number of clients (like a collector sending
reports periodically). On top of the number of clients, many aspects of the simulation are configurable:
number of loops, interval, number of metrics per report, ... etc.

See the scenario file for the list of options.

== Running

mvn gatling:execute -Dxxx=y ...

Each scenario option can be set with a system property.
61 changes: 61 additions & 0 deletions load-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!--
Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
and other contributors as indicated by the @author tags.
Licensed 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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.hawkular.metrics</groupId>
<artifactId>hawkular-metrics-parent</artifactId>
<version>0.3.4-SNAPSHOT</version>
</parent>

<artifactId>hawkular-metrics-load-tests</artifactId>
<name>Hawkular Metrics Load Tests</name>
<packaging>pom</packaging>

<properties>
<version.io.gatling>2.1.6</version.io.gatling>
</properties>

<dependencies>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>${version.io.gatling}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${version.io.gatling}</version>
<configuration>
<simulationClass>org.hawkular.metrics.loadtest.MetricsSimulation</simulationClass>
<propagateSystemProperties>true</propagateSystemProperties>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed 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.hawkular.metrics.loadtest

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class MetricsSimulation extends Simulation {

// --------------------------- Options

val baseURI = System.getProperty("baseURI", "http://localhost:8080")
val tenant = System.getProperty("tenant", "default")

// Number of concurrent clients (think of collectors on different machines)
val clients = Integer.getInteger("clients", 1)
// Delay before firing up another client
val ramp = java.lang.Long.getLong("ramp", 0L)

// The number of loops for each client
val loops = Integer.getInteger("loops", 10).toInt
// Interval between metrics reports
val interval = Integer.getInteger("interval", 1)

// Number of metrics in a JSON report
val metrics = Integer.getInteger("metrics", 10)
// Number of data points for a metric
val points = Integer.getInteger("points", 1)

// ---------------------------

val httpProtocol = http
.baseURL(baseURI)
.header("Hawkular-Tenant", tenant)
.contentTypeHeader("application/json;charset=utf-8")

val random = new util.Random
val genReport = (m: Int, p: Int) => {
val builder = new StringBuilder
builder += '['
for (i <- 1 to m) {
builder ++= """{"id":"metrics.load.test."""
builder.append(i)
builder ++= """.value","data":["""
for (j <- 1 to p) {
builder ++= """{"timestamp":"""
builder.append(System.currentTimeMillis)
builder ++= ""","value":"""
builder.append(random.nextDouble)
builder += '}'
if (j < p) builder += ','
}
builder ++= "]}"
if (i < m) builder += ','
}
builder += ']'
builder.toString
}

val simulation = repeat(loops, "n") {
exec(http("Report ${n}")
.post("/hawkular/metrics/gauges/data")
.body(StringBody(session => genReport(metrics, points)))
).pause(interval)
}

val scn = scenario("MetricsSimulation").exec(simulation)

setUp(scn.inject(rampUsers(clients) over (ramp seconds))).protocols(httpProtocol)
}

1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<module>rest-tests</module>
<module>clients</module>
<module>containers</module>
<module>load-tests</module>
</modules>

<scm>
Expand Down

8 comments on commit 363ba9e

@jkremser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jkremser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scala is now on the classpath because it's a transitive dependency of the swagger, however, we can use the plain Java impl and reduce the size of all component wars significantly. I am currently working on it, once it gets to the parent pom, the Scala dependency needs to be explicitly added for the gatling to be able to run. It can have the test scope.

@tsegismont
Copy link
Contributor Author

@tsegismont tsegismont commented on 363ba9e Jun 3, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkremser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure? Something needs to compile the scala code

@tsegismont
Copy link
Contributor Author

@tsegismont tsegismont commented on 363ba9e Jun 3, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsanda
Copy link
Contributor

@jsanda jsanda commented on 363ba9e Jun 3, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, Gatling runs only the client side. If Scala or any other Gatling dependencies are getting pulled into the metrics WAR, that should be a simple fix.

@jkremser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, the whole scala is now in the war because of the swagger :]

@tsegismont
Copy link
Contributor Author

@tsegismont tsegismont commented on 363ba9e Jun 3, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.