You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/04/16 19:24:41 UTC
[GitHub] dubee closed pull request #3427: Add Gatling tests to test
performance.
dubee closed pull request #3427: Add Gatling tests to test performance.
URL: https://github.com/apache/incubator-openwhisk/pull/3427
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/gatlingtests/README.md b/gatlingtests/README.md
new file mode 100644
index 0000000000..808e9132f6
--- /dev/null
+++ b/gatlingtests/README.md
@@ -0,0 +1,55 @@
+# Gatling Tests
+
+These tests can be used to test the performance of a deployed OpenWhisk-system.
+
+## Simulations
+
+You can specify two thresholds for the simulations.
+The reason is, that Gatling is able to handle each assertion as a JUnit test.
+On using CI/CD pipelines (e.g. Jenkins) you will be able to set a threshold on an amount of failed testcases to mark the build as stable, unstable and failed.
+
+### ApiV1Simulation
+
+This Simulation calls the `api/v1`.
+You can specify the endpoint, the amount of connections against the backend and the duration of this burst.
+
+Available environment variables:
+
+```
+OPENWHISK_HOST (required)
+CONNECTIONS (required)
+SECONDS (default: 10)
+REQUESTS_PER_SEC (required)
+MIN_REQUESTS_PER_SEC (default: REQUESTS_PER_SEC)
+```
+
+You can run the simulation with
+```
+OPENWHISK_HOST="openwhisk.mydomain.com" CONNECTIONS="10" REQUESTS_PER_SEC="50" ./gradlew gatlingRun-ApiV1Simulation
+```
+
+### BlockingInvokeOneActionSimulation
+
+This simulation executes the same action with the same user over and over again.
+The aim of this test is, to test the throughput of the system, if all containers are always warm.
+
+The action that is invoked, writes one log line and returns a little json.
+
+The simulations creates the action in the beginning, invokes it as often as possible for 5 seconds, to warm all containers up and invokes it afterwards for the given amount of time.
+The warmup-phase will not be part of the assertions.
+
+To run the test, you can specify the amount of concurrent requests. Keep in mind, that the actions are invoked blocking and the system is limited to `AMOUNT_OF_INVOKERS * SLOTS_PER_INVOKER * NON_BLACKBOX_INVOKER_RATIO` concurrent actions/requests.
+
+Available environment variables:
+```
+OPENWHISK_HOST (required)
+CONNECTIONS (required)
+SECONDS (default: 10)
+REQUESTS_PER_SEC (required)
+MIN_REQUESTS_PER_SEC (default: REQUESTS_PER_SEC)
+```
+
+You can run the simulation with
+```
+OPENWHISK_HOST="openwhisk.mydomain.com" CONNECTIONS="10" REQUESTS_PER_SEC="50" ./gradlew gatlingRun-BlockingInvokeOneActionSimulation
+```
diff --git a/gatlingtests/build.gradle b/gatlingtests/build.gradle
new file mode 100644
index 0000000000..dc0616f07b
--- /dev/null
+++ b/gatlingtests/build.gradle
@@ -0,0 +1,25 @@
+buildscript {
+ repositories {
+ jcenter()
+ }
+ dependencies {
+ classpath "cz.alenkacz:gradle-scalafmt:1.6.0"
+ }
+}
+
+plugins {
+ id "com.github.lkishalmi.gatling" version "0.7.1"
+}
+
+apply plugin: 'eclipse'
+apply plugin: 'scala'
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ compile "org.scala-lang:scala-library:2.12.4"
+ compile "io.gatling.highcharts:gatling-charts-highcharts:2.2.5"
+ gatling "io.spray:spray-json_2.12:1.3.4"
+}
diff --git a/gatlingtests/src/gatling/resources/conf/logback.xml b/gatlingtests/src/gatling/resources/conf/logback.xml
new file mode 100644
index 0000000000..62bd2b255d
--- /dev/null
+++ b/gatlingtests/src/gatling/resources/conf/logback.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ <immediateFlush>false</immediateFlush>
+ </encoder>
+ </appender>
+ <!-- This will log the details of the failed requests -->
+ <logger name="io.gatling.http.ahc" level="DEBUG" />
+ <root level="WARN">
+ <appender-ref ref="CONSOLE"/>
+ </root>
+</configuration>
diff --git a/gatlingtests/src/gatling/resources/data/dosCPU.js b/gatlingtests/src/gatling/resources/data/dosCPU.js
new file mode 100644
index 0000000000..e70a64bcfb
--- /dev/null
+++ b/gatlingtests/src/gatling/resources/data/dosCPU.js
@@ -0,0 +1,17 @@
+function sleep(milliseconds) {
+ var start = new Date().getTime();
+ while (true) {
+ var now = new Date().getTime();
+ if ((now - start) > milliseconds) {
+ break;
+ }
+ }
+}
+
+function main(msg) {
+ var busytime = msg.busytime || 100;
+ sleep(busytime);
+ var res = '[OK] message terminated successfully after ' + busytime + ' ms.';
+ console.log('dosCPU', 'result:', res);
+ return { msg: res };
+}
diff --git a/gatlingtests/src/gatling/resources/data/nodeJSAction.js b/gatlingtests/src/gatling/resources/data/nodeJSAction.js
new file mode 100644
index 0000000000..4867a4ee04
--- /dev/null
+++ b/gatlingtests/src/gatling/resources/data/nodeJSAction.js
@@ -0,0 +1,8 @@
+function main(params) {
+ var greeting = "Hello stranger!";
+ if (params.text) {
+ greeting = "Hello " + params.text + "!";
+ }
+ console.log(greeting);
+ return { payload: greeting };
+}
diff --git a/gatlingtests/src/gatling/resources/data/users.csv b/gatlingtests/src/gatling/resources/data/users.csv
new file mode 100644
index 0000000000..0975b31d75
--- /dev/null
+++ b/gatlingtests/src/gatling/resources/data/users.csv
@@ -0,0 +1,2 @@
+subject,uuid,key
+guest,23bc46b1-71f6-4ed5-8c54-816aa4f8c502,123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP
diff --git a/gatlingtests/src/gatling/scala/ApiV1Simulation.scala b/gatlingtests/src/gatling/scala/ApiV1Simulation.scala
new file mode 100644
index 0000000000..1f74ec3da8
--- /dev/null
+++ b/gatlingtests/src/gatling/scala/ApiV1Simulation.scala
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+import extension.whisk.Predef._
+import io.gatling.core.Predef._
+
+import scala.concurrent.duration._
+import scala.util.Properties
+
+class ApiV1Simulation extends Simulation {
+
+ // Specify parameters for the run
+ val host = sys.env("OPENWHISK_HOST")
+ val connections = sys.env("CONNECTIONS").toInt
+ val seconds = Properties.envOrElse("SECONDS", "10").toInt.seconds
+
+ // Specify thresholds
+ val requestsPerSec = sys.env("REQUESTS_PER_SEC").toInt
+ val minimalRequestsPerSec = Properties.envOrElse("MIN_REQUESTS_PER_SEC", requestsPerSec.toString).toInt
+
+ // Generate the OpenWhiskProtocol
+ val openWhiskProtocol = openWhisk.apiHost(host)
+
+ // Define scenario
+ val test = scenario("api/v1 endpoint")
+ .during(seconds) {
+ exec(openWhisk("Call api/v1 endpoint").info())
+ }
+
+ setUp(test.inject(atOnceUsers(connections)))
+ .protocols(openWhiskProtocol)
+ // One failure will make the build yellow
+ .assertions(details("Call api/v1 endpoint").requestsPerSec.gt(minimalRequestsPerSec))
+ .assertions(details("Call api/v1 endpoint").requestsPerSec.gt(requestsPerSec))
+ // Mark the build yellow, if there are failed requests. And red if both conditions fail.
+ .assertions(details("Call api/v1 endpoint").failedRequests.count.is(0))
+ .assertions(details("Call api/v1 endpoint").failedRequests.percent.lte(0.1))
+}
diff --git a/gatlingtests/src/gatling/scala/BlockingInvokeOneActionSimulation.scala b/gatlingtests/src/gatling/scala/BlockingInvokeOneActionSimulation.scala
new file mode 100644
index 0000000000..704bdea6b9
--- /dev/null
+++ b/gatlingtests/src/gatling/scala/BlockingInvokeOneActionSimulation.scala
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+import extension.whisk.Predef._
+import io.gatling.core.Predef._
+
+import scala.concurrent.duration._
+import scala.util.Properties
+
+class BlockingInvokeOneActionSimulation extends Simulation {
+ // Specify parameters for the run
+ val host = sys.env("OPENWHISK_HOST")
+ val connections = sys.env("CONNECTIONS").toInt
+ val seconds = Properties.envOrElse("SECONDS", "10").toInt.seconds
+
+ // Specify thresholds
+ val requestsPerSec = sys.env("REQUESTS_PER_SEC").toInt
+ val minimalRequestsPerSec = Properties.envOrElse("MIN_REQUESTS_PER_SEC", requestsPerSec.toString).toInt
+
+ // Generate the OpenWhiskProtocol
+ val openWhiskProtocol = openWhisk.apiHost(host)
+
+ val actionName = "testActionForBlockingInvokeOneAction"
+
+ // Load first user from CSV
+ // Fails directly if that does not work
+ val line = csv("users.csv").records.head
+ val uuid = line.get("uuid").get
+ val key = line.get("key").get
+
+ // Define scenario
+ val test = scenario("Invoke one action blocking")
+ .doIf(_.userId == 1) {
+ exec(openWhisk("Create action").authenticate(uuid, key).actionCreate(actionName, "nodeJSAction.js"))
+ }
+ .rendezVous(connections)
+ .during(5.seconds) {
+ exec(openWhisk("Warm containers up").authenticate(uuid, key).actionInvoke(actionName, blocking = true))
+ }
+ .rendezVous(connections)
+ .during(seconds) {
+ exec(openWhisk("Invoke action").authenticate(uuid, key).actionInvoke(actionName, blocking = true))
+ }
+ .rendezVous(connections)
+ .doIf(_.userId == 1) {
+ exec(openWhisk("Delete action").authenticate(uuid, key).actionDelete(actionName))
+ }
+
+ setUp(test.inject(atOnceUsers(connections)))
+ .protocols(openWhiskProtocol)
+ // One failure will make the build yellow
+ .assertions(details("Invoke action").requestsPerSec.gt(minimalRequestsPerSec))
+ .assertions(details("Invoke action").requestsPerSec.gt(requestsPerSec))
+ // Mark the build yellow, if there are failed requests. And red if both conditions fail.
+ .assertions(details("Invoke action").failedRequests.count.is(0))
+ .assertions(details("Invoke action").failedRequests.percent.lte(0.1))
+}
diff --git a/gatlingtests/src/gatling/scala/extension/whisk/OpenWhiskActionBuilder.scala b/gatlingtests/src/gatling/scala/extension/whisk/OpenWhiskActionBuilder.scala
new file mode 100644
index 0000000000..6da6821385
--- /dev/null
+++ b/gatlingtests/src/gatling/scala/extension/whisk/OpenWhiskActionBuilder.scala
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+
+package extension.whisk
+
+import io.gatling.core.Predef._
+import io.gatling.core.action.Action
+import io.gatling.core.action.builder.ActionBuilder
+import io.gatling.core.session.Expression
+import io.gatling.core.structure.ScenarioContext
+import io.gatling.core.util.Resource
+import io.gatling.http.Predef._
+import io.gatling.http.request.builder.{Http, HttpRequestBuilder}
+import spray.json.DefaultJsonProtocol._
+import spray.json._
+
+import scala.io.Source
+
+case class OpenWhiskActionBuilderBase(requestName: Expression[String]) {
+
+ implicit private val http = new Http(requestName)
+
+ def info() = OpenWhiskActionBuilder(http.get("/api/v1"))
+ def authenticate(uuid: String, key: String) = OpenWhiskActionBuilderWithNamespace(uuid, key)
+}
+
+case class OpenWhiskActionBuilderWithNamespace(private val uuid: String,
+ private val key: String,
+ private val namespace: String = "_")(implicit private val http: Http) {
+
+ def namespace(namespace: String) = OpenWhiskActionBuilderWithNamespace(uuid, key, namespace)
+ def actionInvoke(actionName: String, blocking: Boolean = false) = {
+ OpenWhiskActionBuilderActionInvoke(
+ http
+ .post(s"/api/v1/namespaces/$namespace/actions/$actionName?blocking=${blocking.toString}")
+ .basicAuth(uuid, key)
+ .check(status.is(if (blocking) 200 else 202)))
+ }
+ def actionCreate(actionName: String, fileName: String, kind: String = "nodejs:default") =
+ OpenWhiskActionBuilder(
+ http
+ .put(s"/api/v1/namespaces/$namespace/actions/$actionName")
+ .basicAuth(uuid, key)
+ .body(createActionCreateBody(fileName, kind)))
+ def actionDelete(actionName: String) =
+ OpenWhiskActionBuilder(http.delete(s"/api/v1/namespaces/$namespace/actions/$actionName").basicAuth(uuid, key))
+
+ private def createActionCreateBody(fileName: String, kind: String) = {
+ val code = Source.fromFile(Resource.feeder(fileName).get.file).mkString
+ val json = JsObject("exec" -> JsObject("kind" -> JsString(kind), "code" -> JsString(code)))
+ StringBody(json.compactPrint)
+ }
+}
+
+case class OpenWhiskActionBuilderActionInvoke(http: HttpRequestBuilder, parameters: Map[String, String] = Map()) {
+
+ def withParameters(key: String, value: String) =
+ OpenWhiskActionBuilderActionInvoke(http, parameters ++ Map((key, value)))
+ def build = OpenWhiskActionBuilder(http.body(StringBody(parameters.toJson.compactPrint)))
+}
+
+object OpenWhiskActionBuilderActionInvoke {
+ implicit def toOpenWhiskActionBuilder(builder: OpenWhiskActionBuilderActionInvoke): OpenWhiskActionBuilder =
+ builder.build
+}
+
+case class OpenWhiskActionBuilder(http: HttpRequestBuilder) extends ActionBuilder {
+ override def build(ctx: ScenarioContext, next: Action): Action = {
+ http.build(ctx, next)
+ }
+}
diff --git a/gatlingtests/src/gatling/scala/extension/whisk/OpenWhiskDsl.scala b/gatlingtests/src/gatling/scala/extension/whisk/OpenWhiskDsl.scala
new file mode 100644
index 0000000000..ea51847433
--- /dev/null
+++ b/gatlingtests/src/gatling/scala/extension/whisk/OpenWhiskDsl.scala
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+package extension.whisk
+
+import io.gatling.core.session.Expression
+
+trait OpenWhiskDsl {
+ def openWhisk = OpenWhiskProtocolBuilderBase
+
+ def openWhisk(requestName: Expression[String]) = new OpenWhiskActionBuilderBase(requestName)
+}
diff --git a/gatlingtests/src/gatling/scala/extension/whisk/OpenWhiskProtocolBuilder.scala b/gatlingtests/src/gatling/scala/extension/whisk/OpenWhiskProtocolBuilder.scala
new file mode 100644
index 0000000000..b16485d260
--- /dev/null
+++ b/gatlingtests/src/gatling/scala/extension/whisk/OpenWhiskProtocolBuilder.scala
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+package extension.whisk
+
+import com.softwaremill.quicklens._
+import io.gatling.core.Predef._
+import io.gatling.core.config.GatlingConfiguration
+import io.gatling.http.Predef._
+import io.gatling.http.protocol.HttpProtocol
+
+/**
+ * This is the OpenWhiskProtocol.
+ *
+ * @param apiHost url or address to connect to
+ * @param protocol protocol to use. e.g. https
+ * @param port port to use. e.g. 443
+ */
+case class OpenWhiskProtocol(apiHost: String, protocol: String = "https", port: Int = 443)
+
+case object OpenWhiskProtocolBuilderBase {
+ def apiHost(url: String): OpenWhiskProtocolBuilder = OpenWhiskProtocolBuilder(OpenWhiskProtocol(url))
+}
+
+object OpenWhiskProtocolBuilder {
+
+ /** convert the OpenWhiskProtocolBuilder to an HttpProtocol. */
+ implicit def toHttpProtocol(builder: OpenWhiskProtocolBuilder)(
+ implicit configuration: GatlingConfiguration): HttpProtocol = builder.build
+}
+
+case class OpenWhiskProtocolBuilder(private val protocol: OpenWhiskProtocol) {
+
+ /** set the api host */
+ def apiHost(url: String): OpenWhiskProtocolBuilder = this.modify(_.protocol.apiHost).setTo(url)
+
+ /** set the protocol */
+ def protocol(protocol: String): OpenWhiskProtocolBuilder = this.modify(_.protocol.protocol).setTo(protocol)
+
+ /** set the port */
+ def port(port: Int): OpenWhiskProtocolBuilder = this.modify(_.protocol.port).setTo(port)
+
+ /** build the http protocol with the parameters provided by the openwhisk-protocol. */
+ def build(implicit configuration: GatlingConfiguration) = {
+ http
+ .baseURL(s"${protocol.protocol}://${protocol.apiHost}:${protocol.port}")
+ .contentTypeHeader("application/json")
+ .userAgentHeader("gatlingLoadTest")
+ .build
+ }
+}
diff --git a/gatlingtests/src/gatling/scala/extension/whisk/Predef.scala b/gatlingtests/src/gatling/scala/extension/whisk/Predef.scala
new file mode 100644
index 0000000000..5733f7d24c
--- /dev/null
+++ b/gatlingtests/src/gatling/scala/extension/whisk/Predef.scala
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+package extension.whisk
+
+object Predef extends OpenWhiskDsl
diff --git a/settings.gradle b/settings.gradle
index 4c76198dbf..4626853cfb 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -17,6 +17,7 @@ include 'sdk:docker'
include 'tests'
include 'tests:dat:blackbox:badaction'
include 'tests:dat:blackbox:badproxy'
+include 'gatlingtests'
rootProject.name = 'openwhisk'
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services