-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a Gatling load testing scenario
- Loading branch information
1 parent
09d7454
commit 363ba9e
Showing
4 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
88 changes: 88 additions & 0 deletions
88
load-tests/src/test/scala/org/hawkular/metrics/loadtest/MetricsSimulation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
363ba9e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
363ba9e
There was a problem hiding this comment.
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.363ba9e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
363ba9e
There was a problem hiding this comment.
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
363ba9e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
363ba9e
There was a problem hiding this comment.
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.
363ba9e
There was a problem hiding this comment.
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 :]
363ba9e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.