Download presentation
Presentation is loading. Please wait.
Published byAmberlynn Black Modified over 7 years ago
1
Performance testing with Gatling
2
Intro/Agenda Performance testing overview Gatling overview Gatling test structure Gatling API Gatling Recorder Gatling DSL Gatling reports
3
Performance testing
4
Measure response time under workload Load, Stress, Soak, Spike testing Find bottlenecks Satisfy impatient customers Increase conversion rate Sustain company reputation
5
Approach 1.Set proper goals 2.Choose tools 3.Try the tools 4.Implement scenarios 5.Prepare environments 6.Run and measure
6
Gatling overview
7
Firepower Gatling
8
Thousands of concurrent users Users are not threads, but actors Asynchronous concurrency Scala Akka Netty Recorder (HTTP Proxy and HAR) Extensions (Maven, Gradle, Jenkins)
9
1 thread = 1 user * * http://www.slideshare.net/ZeroTurnaround/stephane-landelleblastyourappwithgatling
10
Blocking I/O * * http://www.slideshare.net/ZeroTurnaround/stephane-landelleblastyourappwithgatling
11
Actors Model Mathematical model used in parallel computing Actor is autonomous computational unit No shared resources, no shared state Asynchronous message passing Mailbox to buffer incoming messages React on received messages
12
Gatling test structure
13
Building blocks
14
Gatling API
15
val myHttpGetRequest = http("Open home page").get("/home") HTTP GET Request Define constant variable Variable name Create HTTP Request object Request name Method of HTTP Request object Request URI
16
val myHttpProtocol = http.baseURL("http://localhost:81") HTTP Protocol Create HTTP Protocol object URL is prepended to any HTTP request Application URL
17
val myScenario = scenario("Browse Home").exec(myHttpGetRequest).pause(2).exec(myReq2) Scenario Create Scenario object Scenario name Execute HTTP Request Already created HTTP Request object Pause time in seconds Pause between requests Execute more HTTP Requests
18
setUp(myScenario.inject(atOnceUsers(10))).protocols(myHttpProtocol) setUp Gatling Simulation base method Scenario object method Number of users Already created HTTP Protocol object Already created Scenario object Injection profile Configure protocol
19
import io.gatling.core.Predef._ import io.gatling.http.Predef._ class MySimulation extends Simulation { } Simulation class Gatling base simulation class Import Gatling API classes Simulation class name
20
Gatling simulation import io.gatling.core.Predef._ import io.gatling.http.Predef._ class MySimulation extends Simulation { val myHttpProtocol = http.baseURL("http://localhost:81").inferHtmlResources() val myHttpGetRequest = http("Open home page").get("/home") val myLoginRequest = http("Open login page").get("/login") val myScenario = scenario("Browse Home").exec(myHttpGetRequest).pause(2).exec(myLoginRequest) setUp(myScenario.inject(atOnceUsers(10))).protocols(myHttpProtocol) }
21
Gatling Recorder
23
Recorded simulation import io.gatling.core.Predef._ import io.gatling.http.Predef._ class RecordedSimulation extends Simulation { val httpProtocol = http.baseURL("http://localhost:9000").inferHtmlResources() val scn = scenario("RecordedSimulation").exec(http("request_0").get("/products")).pause(5).exec(http("request_1").get("/products?q=SearchString")) setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol) }
24
Gatling DSL Domain Specific Language
25
Gatling DSL Feeders csv, ssv, tsv, jsonFile, jsonUrl, jdbcFeeder queue, random, circular Checks responseTimeInMillis, latencyInMillis, status, currentLocation header, headerRegex bodyString, bodyBytes, regex, xpath, jsonPath, css Check actions find, findAll, count, saveAs is, not, exits, notExists, in, optional
26
Gatling DSL (2) Execution control doIf, doIfOrElse, doSwitch, doSwitchOrElse, randomSwitch repeat, foreach, during, asLongAs, forever tryMax, exitBlockOnFail, exitHereIfFailed Assertions responseTime, allRequests, requestsPerSec min, max, mean, stdDev, percentile1, percentile2 lessThan, greaterThan, between, is, in, assert Injection profiles nothingFor, atOnceUsers, rampUsers over, rampUsers during
27
Session A virtual user’s state stores all simulation user’s data Map[String, Any] Write data using Feeders extract and save from response programmatically with Session API Read data using Gatling Expression Language programmatically with Session API
28
Gatling reports
31
STIONS ? ANY
32
Thank you! Lyudmil Latinov Senior Automation QA Xoomworks Bulgaria https://github.com/llatinov/sample-performance-with-gatling Blog: AutomationRhapsody.comAutomationRhapsody.com www.qachallengeaccepted.com
33
Bonus slides Offline bonus slides
34
private val csvFeeder = csv("search_terms.csv").circular.random CSV Feeder Access modifier Read CSV file CSV file name Start over once file is read CSV file content First line is header, used as session variable name search_term prod product1 hello searchTerm1 hello hellosearch_terms.csv Access in random order
35
val scn = scenario("Search products").feed(csvFeeder).forever() { exec(http("Search product").get("/products?q=${search_term}")) } Use CSV Feeder Add Feeder to Scenario object Already created CSV Feeder object Iterate scenario forever Execute HTTP Requests in body HTTP GET Request Access CSV data by header with Gatling EL
36
val reqSavePerson = http("Save Person").post("/person/save").body(ElFileBody("person.json")).header("Content-Type", "application/json") HTTP POST Request Create HTTP Post Request object Request URI { "id": "${id}", "firstName": "${first_name}", "lastName": "${last_name}", "email": "${email}" }person.json Add header field Add body to HTTP Post request Read body file and parse with Gatling EL File name Gatling EL parser replaces session variables
37
val myProtocol = http.baseURL("http://localhost:81").check(status.is(200)) val myRequest = http("Home").get("/home").check(regex("Hello, (*.?) (*.?)!")) Checks Checks can be defined on HTTP Protocol level Add check to HTTP Protocol object Response code is 200 OK Usually check are defined on HTTP Request level Add check to HTTP Request object Response body matches regular expression
38
val reqSearch = http("Search product").get("/products?q=${search_term}").check(regex("Found ([\\d]{1,4}) products:").saveAs("numberOfProducts")) Save to Session HTTP GET Request Access session data with Gatling EL Check response body matches specific regex Save regular expression matched group Name of session variable to save to
39
val reqOpenProduct = exec(session => { var prds = session("numberOfProducts").as[String].toInt var productId = Random.nextInt(prds) + 1 session.set("productId", productId) }).exec(http("Open").get("/products?id=${productId}")) Manage Session variables Access Session objectinside exec block with lambda Some test logic Execute HTTP Get request Variable is accessible only on second exec block Create and return new Session object with variable saved in it Read variable from Session object as String and convert to Integer
40
val scnLogoutOrHome = scenario("Logout Or Home").doIfEqualsOrElse("${action}", "Logout") { exec(http("Do logout").get("/logout")) } { exec(http("Home page").get("/home")) } Conditional execution Conditions are calculated on Scenario object If Session variable equals given value Execute Requests chain in case of FALSE Execute Requests chain in case of TRUE
41
setUp(scnSearch.inject(rampUsers(10) over 10.seconds), scnOpenProduct.inject(atOnceUsers(10))).protocols(myProtocol).maxDuration(10.minutes).assertions( global.responseTime.max.lessThan(800), global.successfulRequests.percent.greaterThan(99) ) Advanced setUp Maximum duration in case of forever() Assert each response time is bellow 800ms Different scenarios with different injection profiles Assert 99% success responses for the Simulation
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.