Performance testing with Gatling IntroAgenda Performance testing overview

  • Slides: 41
Download presentation
Performance testing with Gatling

Performance testing with Gatling

Intro/Agenda • Performance testing overview • Gatling test structure • Gatling API • Gatling

Intro/Agenda • Performance testing overview • Gatling test structure • Gatling API • Gatling Recorder • Gatling DSL • Gatling reports

Performance testing

Performance testing

Performance testing • Measure response time under workload • Load, Stress, Soak, Spike testing

Performance testing • Measure response time under workload • Load, Stress, Soak, Spike testing • Find bottlenecks • Satisfy impatient customers • Increase conversion rate • Sustain company reputation

Approach 1. 2. 3. 4. 5. 6. Set proper goals Choose tools Try the

Approach 1. 2. 3. 4. 5. 6. Set proper goals Choose tools Try the tools Implement scenarios Prepare environments Run and measure

Gatling overview

Gatling overview

Gatling e r i F w o p r e

Gatling e r i F w o p r e

Gatling • Thousands of concurrent users • Users are not threads, but actors •

Gatling • Thousands of concurrent users • Users are not threads, but actors • Asynchronous concurrency • Scala • Akka • Netty • Recorder (HTTP Proxy and HAR) • Extensions (Maven, Gradle, Jenkins)

1 thread = 1 user * * http: //www. slideshare. net/Zero. Turnaround/stephane-landelleblastyourappwithgatling

1 thread = 1 user * * http: //www. slideshare. net/Zero. Turnaround/stephane-landelleblastyourappwithgatling

Blocking I/O * * http: //www. slideshare. net/Zero. Turnaround/stephane-landelleblastyourappwithgatling

Blocking I/O * * http: //www. slideshare. net/Zero. Turnaround/stephane-landelleblastyourappwithgatling

Actors Model • Mathematical model used in parallel computing • Actor is autonomous computational

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

Gatling test structure

Gatling test structure

Building blocks

Building blocks

Gatling API

Gatling API

HTTP GET Request Define constant variable Variable name Method of HTTP Request object Request

HTTP GET Request Define constant variable Variable name Method of HTTP Request object Request URI val my. Http. Get. Request = http("Open home page"). get("/home") Create HTTP Request object Request name

HTTP Protocol Create HTTP Protocol object URL is prepended to any HTTP request Application

HTTP Protocol Create HTTP Protocol object URL is prepended to any HTTP request Application URL val my. Http. Protocol = http. base. URL("http: //localhost: 81")

Scenario Create Scenario object Scenario name Execute HTTP Request Already created HTTP Request object

Scenario Create Scenario object Scenario name Execute HTTP Request Already created HTTP Request object val my. Scenario = scenario("Browse Home"). exec(my. Http. Get. Request). pause(2). exec(my. Req 2) Pause between requests Pause time in seconds Execute more HTTP Requests

set. Up Gatling Simulation base method Scenario object method Number of users Already created

set. Up Gatling Simulation base method Scenario object method Number of users Already created HTTP Protocol object set. Up(my. Scenario. inject(at. Once. Users(10))). protocols(my. Http. Protocol) Already created Scenario object Injection profile Configure protocol

Simulation class Import Gatling API classes Gatling base simulation class import io. gatling. core.

Simulation class Import Gatling API classes Gatling base simulation class import io. gatling. core. Predef. _ import io. gatling. http. Predef. _ class My. Simulation extends Simulation { } Simulation class name

Gatling simulation import io. gatling. core. Predef. _ import io. gatling. http. Predef. _

Gatling simulation import io. gatling. core. Predef. _ import io. gatling. http. Predef. _ class My. Simulation extends Simulation { val my. Http. Protocol = http. base. URL("http: //localhost: 81"). infer. Html. Resources() val my. Http. Get. Request = http("Open home page"). get("/home") val my. Login. Request = http("Open login page"). get("/login") val my. Scenario = scenario("Browse Home"). exec(my. Http. Get. Request). pause(2). exec(my. Login. Request) set. Up(my. Scenario. inject(at. Once. Users(10))). protocols(my. Http. Protocol) }

Gatling Recorder

Gatling Recorder

Recorded simulation import io. gatling. core. Predef. _ import io. gatling. http. Predef. _

Recorded simulation import io. gatling. core. Predef. _ import io. gatling. http. Predef. _ class Recorded. Simulation extends Simulation { val http. Protocol = http. base. URL("http: //localhost: 9000"). infer. Html. Resources() val scn = scenario("Recorded. Simulation"). exec(http("request_0"). get("/products")). pause(5). exec(http("request_1"). get("/products? q=Search. String")) set. Up(scn. inject(at. Once. Users(1))). protocols(http. Protocol) }

Gatling DSL Domain Specific Language

Gatling DSL Domain Specific Language

Gatling DSL • Feeders • csv, ssv, tsv, json. File, json. Url, jdbc. Feeder

Gatling DSL • Feeders • csv, ssv, tsv, json. File, json. Url, jdbc. Feeder • queue, random, circular • Checks • response. Time. In. Millis, latency. In. Millis, status, current. Location • header, header. Regex • body. String, body. Bytes, regex, xpath, json. Path, css • Check actions • find, find. All, count, save. As • is, not, exits, not. Exists, in, optional

Gatling DSL (2) • Execution control • do. If, do. If. Or. Else, do.

Gatling DSL (2) • Execution control • do. If, do. If. Or. Else, do. Switch. Or. Else, random. Switch • repeat, foreach, during, as. Long. As, forever • try. Max, exit. Block. On. Fail, exit. Here. If. Failed • Assertions • response. Time, all. Requests, requests. Per. Sec • min, max, mean, std. Dev, percentile 1, percentile 2 • less. Than, greater. Than, between, is, in, assert • Injection profiles • nothing. For, at. Once. Users, ramp. Users over, ramp. Users during

Session • A virtual user’s state • stores all simulation user’s data • Map[String,

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

Gatling reports

Gatling reports

ANY STIONS?

ANY STIONS?

Thank you! Lyudmil Latinov Senior Automation QA Xoomworks Bulgaria https: //github. com/llatinov/sample-performance-with-gatling Blog: Automation.

Thank you! Lyudmil Latinov Senior Automation QA Xoomworks Bulgaria https: //github. com/llatinov/sample-performance-with-gatling Blog: Automation. Rhapsody. com www. qachallengeaccepted. com

Bonus slides Offline bonus slides

Bonus slides Offline bonus slides

CSV Feeder Access modifier Read CSV file name Start over once file is read

CSV Feeder Access modifier Read CSV file name Start over once file is read Access in random order private val csv. Feeder = csv("search_terms. csv"). circular. random search_terms. csv CSV file content First line is header, used as session variable name search_term product 1 hello search. Term 1 hello

Use CSV Feeder Add Feeder to Scenario object Already created CSV Feeder object Iterate

Use CSV Feeder Add Feeder to Scenario object Already created CSV Feeder object Iterate scenario forever val scn = scenario("Search products"). feed(csv. Feeder). forever() { exec(http("Search product"). get("/products? q=${search_term}")) } Execute HTTP Requests in body HTTP GET Request Access CSV data by header with Gatling EL

HTTP POST Request person. json { "id": "${id}", "first. Name": "${first_name}", "last. Name": "${last_name}",

HTTP POST Request person. json { "id": "${id}", "first. Name": "${first_name}", "last. Name": "${last_name}", "email": "${email}" Gatling EL parser replaces session variables Create HTTP Post Request object Request URI } val req. Save. Person = http("Save Person"). post("/person/save"). body(El. File. Body("person. json")). header("Content-Type", "application/json") Add body to HTTP Post request Read body file and parse with Gatling EL File name Add header field

Checks can be defined on HTTP Protocol level Add check to HTTP Protocol object

Checks can be defined on HTTP Protocol level Add check to HTTP Protocol object Response code is 200 OK val my. Protocol = http. base. URL("http: //localhost: 81"). check(status. is(200)) val my. Request = http("Home"). get("/home"). check(regex("Hello, (*. ? )!")) Usually check are defined on HTTP Request level Add check to HTTP Request object Response body matches regular expression

Save to Session HTTP GET Request Access session data with Gatling EL val req.

Save to Session HTTP GET Request Access session data with Gatling EL val req. Search = http("Search product"). get("/products? q=${search_term}"). check(regex("Found ([\d]{1, 4}) products: "). save. As("number. Of. Products")) Check response body matches specific regex Save regular expression matched group Name of session variable to save to

Manage Session variables Access Session objectinside exec block with lambda Read variable from Session

Manage Session variables Access Session objectinside exec block with lambda Read variable from Session object as String and convert to Integer val req. Open. Product = exec(session => { var prds = session("number. Of. Products"). as[String]. to. Int Some test logic var product. Id = Random. next. Int(prds) + 1 session. set("product. Id", product. Id) Create and return new }). exec(http("Open"). get("/products? id=${product. Id}")) Session object with variable saved in it Execute HTTP Get request Variable is accessible only on second exec block

Conditional execution Conditions are calculated on Scenario object If Session variable equals given value

Conditional execution Conditions are calculated on Scenario object If Session variable equals given value val scn. Logout. Or. Home = scenario("Logout Or Home"). do. If. Equals. Or. Else("${action}", "Logout") { exec(http("Do logout"). get("/logout")) Execute Requests chain } { in case of TRUE exec(http("Home page"). get("/home")) } Execute Requests chain in case of FALSE

Advanced set. Up Different scenarios with different injection profiles set. Up(scn. Search. inject(ramp. Users(10)

Advanced set. Up Different scenarios with different injection profiles set. Up(scn. Search. inject(ramp. Users(10) over 10. seconds), scn. Open. Product. inject(at. Once. Users(10))). protocols(my. Protocol). max. Duration(10. minutes). assertions( global. response. Time. max. less. Than(800), global. successful. Requests. percent. greater. Than(99) ) Maximum duration in case of forever() Assert each response time is bellow 800 ms Assert 99% success responses for the Simulation