diff --git a/README.md b/README.md index 422df46..d0ab1c0 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,24 @@ Scripts for provisioning and benchmarking clamp core performance * brew install scala@2.12 +## Running Clamp +Clamp and its dependencies can be run with the following Docker Compose command + +```bash +$ docker-compose -d up +``` + +## Running Tests + +```bash +$ mvn gatling:test -DgatlingSimulationClass=clampcore.{simulation-class-name} -D{arg-name}={arg-value} +``` + +**Simulation Classes** +- `InitiateWorkflowSimulation` - Tests workflow creation, service request creation and service status polling APIs +- `CreateServiceRequestSimulation` - Tests service request creation API + +**Example** +```bash +$ mvn gatling:test -DgatlingSimulationClass=clampcore.CreateServiceRequestSimulation -DmaxRPS=500 -DdurationSeconds=120 -DmaxDurationSeconds=300 +``` \ No newline at end of file diff --git a/benchmarking/pom.xml b/benchmarking/pom.xml index 328ecc0..bb8f956 100644 --- a/benchmarking/pom.xml +++ b/benchmarking/pom.xml @@ -70,7 +70,7 @@ -DdurationMaxMinutes=${durationMaxSeconds} -Xmx5g - clampcore.InitiateWorkflowSimulation + ${gatlingSimulationClass} true diff --git a/benchmarking/src/test/scala/clampcore/CreateServiceRequestSimulation.scala b/benchmarking/src/test/scala/clampcore/CreateServiceRequestSimulation.scala new file mode 100644 index 0000000..e3e5f82 --- /dev/null +++ b/benchmarking/src/test/scala/clampcore/CreateServiceRequestSimulation.scala @@ -0,0 +1,90 @@ +package clampcore + +import io.gatling.core.Predef._ +import io.gatling.core.feeder.Feeder +import io.gatling.http.Predef._ +import org.slf4j.{Logger, LoggerFactory} + +import java.util.UUID +import scala.concurrent.duration._ +import scala.language.postfixOps + +class CreateServiceRequestSimulation extends Simulation { + + var logger: Logger = LoggerFactory.getLogger("SimulationLogger") + val MAX_RPS = Integer.getInteger("maxRPS", 500).toDouble + val DURATION_SECONDS = Integer.getInteger("durationSeconds", 120).toInt + val MAX_DURATION_SECONDS = Integer.getInteger("maxDurationSeconds", 300).toInt + + var workflowName = "" + + val workflowDefinition = + """ + { + "name": "${workflow_name}", + "description": "a benchmarking flow with only http sync services", + "steps": [ + { + "name": "benchmarking step one", + "mode": "HTTP", + "val": { + "method": "GET", + "url": "http://api-server:8083/api/step1" + } + } + ] + } + """ + + val baseHttp = http + .baseUrl("http://localhost:8080") + .header("no-cache", "no-cache") + .contentTypeHeader("application/json") + .userAgentHeader("PostmanRuntime/7.26.8") + .acceptHeader("*/*") + .connectionHeader("keep-alive") + + val uuidfeeder: Feeder[String] = Iterator.continually(Map("workflow_name" -> UUID.randomUUID().toString)) + + def createWorkflow() = { + exec(http("create_workflow") + .post("/workflow") + .body(StringBody(workflowDefinition)).asJson + .check(jsonPath("$.name").saveAs("workflowName")) + ) + } + + def createServiceRequest() = { + http("execute_workflow") + .post("/serviceRequest/${workflow_name}") + .check(status.is(200)) + } + + var createWorkflowScenario = scenario("Create workflow scenario") + .feed(uuidfeeder) + .exec(createWorkflow()) + .exec(session => { + workflowName = session("workflowName").as[String] + session + }) + + var createPollServiceRequestScenario = scenario("Create service request scenario") + .exec(_.set("workflow_name", workflowName)) + .exec(createServiceRequest()) + + setUp( + List( + createWorkflowScenario.inject( + atOnceUsers(1) + ) + .protocols(baseHttp) + .andThen( + createPollServiceRequestScenario.inject( + rampUsersPerSec(1).to(MAX_RPS).during(DURATION_SECONDS seconds) + ) + .protocols(baseHttp) + ) + ) + ) + .maxDuration(MAX_DURATION_SECONDS seconds) +}