Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

TestWorks Conf Performance testing made easy with gatling - Guillaume Corré

1,004 views

Published on

The applications we build have to deal with more and more data and users and having them perform poorly could hurt business pretty bad.

Yet, performance testing is usually not properly dealt with. Too many organizations just throw this brick over the wall to a team that knows nothing of the project, and do so only once the project is almost complete and it's too late to fix it.

While implementing multiple scenarios, we will go through most issues our users encounter and show you how to solve them.

Published in: Technology
  • Be the first to comment

TestWorks Conf Performance testing made easy with gatling - Guillaume Corré

  1. 1. © Gatling 2015.All rights reserved. Requirements Background in programming 1. Object oriented language mostly 2. Functional programming is a plus, but optional Experience 1. Gatling? 2. Scala? 1
  2. 2. © Gatling 2015.All rights reserved. LoadTesting Done Right http://gatling.io Guillaume Corré @notdryft 2
  3. 3. © Gatling 2015.All rights reserved. Workshop Schedule 1. Architecture 2. Usage 3. Exercises 3
  4. 4. © Gatling 2015.All rights reserved. Workshop Schedule 1. Architecture 2. Usage 3. Exercises 4
  5. 5. © Gatling 2015.All rights reserved. Gatling:Architecture Designed for: 1. Complex use cases 2. High Performance 3. Maintainability 5
  6. 6. © Gatling 2015.All rights reserved. Gatling:Architecture High Performance Optimize thread usage: 1. Non Blocking IO 2. Message oriented orchestration 6
  7. 7. © Gatling 2015.All rights reserved. Gatling:Architecture High Performance 7
  8. 8. © Gatling 2015.All rights reserved. Gatling:Architecture Maintainability Code 1. Real programming language 2. DSL 3. API 8
  9. 9. © Gatling 2015.All rights reserved. Gatling:Architecture Maintainability Why? 1. Versioning 2. Refactoring 3. Peer review 4. Composition 9
  10. 10. © Gatling 2015.All rights reserved. Gatling:Architecture Maintainability 10 class Simple extends Simulation { val scn = scenario("simple") .exec( http("home") .get("http://gatling.io") .check(status.is(200))) setUp( scn.inject( atOnceUsers(1))) }
  11. 11. © Gatling 2015.All rights reserved. Workshop Schedule 1. Architecture 2. Usage 3. Exercises 11
  12. 12. © Gatling 2015.All rights reserved. Gatling: Usage 12
  13. 13. © Gatling 2015.All rights reserved. Usage: DSL Extensive documentation: http://gatling.io/#/docs Cheat-sheet: http://gatling.io/docs/2.1.7/cheat-sheet.html 13
  14. 14. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 1: Create a Simulation class 14 import io.gatling.core.Predef._ import io.gatling.http.Predef._ import scala.concurrent.duration._ class Simple extends Simulation { }
  15. 15. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 2: Create a Scenario 15 import … class Simple extends Simulation { val scn = scenario("simple") }
  16. 16. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 3: Chain Actions 16 import … class Simple extends Simulation { val scn = scenario("simple") .exec( http("home") .get("http://gatling.io")) }
  17. 17. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 4: Check your requests are fine 17 import … class Simple extends Simulation { val scn = scenario("simple") .exec( http("home") .get("http://gatling.io") .check(status.is(200)) }
  18. 18. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 5: Set up and inject users 18 import … class Simple extends Simulation { val scn = scenario("simple") .exec( http("home") .get("http://gatling.io") .check(status.is(200)) setUp(scn.inject(atOnceUsers(1))) }
  19. 19. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 6: Make things dynamic 19 // Set up virtual users with feeders feed(csv("credentials.csv"))
  20. 20. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 6: Make things dynamic 20 // Capture response data with checks http("request") .get("url") .check(css("someSelector").saveAs("someVariable"))
  21. 21. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 6: Make things dynamic 21 // Craft requests with the Expression Language http("request") .get("/foo?bar=${someVariable}")
  22. 22. © Gatling 2015.All rights reserved. Usage:Very Fast Track Step 6: Make things dynamic 22 // Use functions exec { session => println(session) session }
  23. 23. © Gatling 2015.All rights reserved. Usage:Very Fast Track Expressions 23 type Expression[T] = Session => Validation[T]
  24. 24. © Gatling 2015.All rights reserved. Workshop Schedule 1. Architecture 2. Usage 3. Exercises 24
  25. 25. © Gatling 2015.All rights reserved. Workshop 4 exercises 1. Ranged from (almost) easy to difficult 2. Each pinpoint different specifics of Gatling Url bit.ly/gatling-workshop Documentation reminder http://gatling.io/#/docs http://gatling.io/docs/2.1.7/cheat-sheet.html 25
  26. 26. © Gatling 2015.All rights reserved. Exercise 1: 1. First Request What happens if you don't do any checks? 1. Gatling adds a status check by default 26
  27. 27. © Gatling 2015.All rights reserved. Exercise 1: 1. First Request Are there any defaults? If so, which? 1. status.in 2. All statuses of the 20x family 3. 304 27
  28. 28. © Gatling 2015.All rights reserved. Exercise 1: 3. Checks Which check should you use to fetch the title ? 1. Regex 1. Most the time harder to maintain 2. Still does the job pretty well 2. XPath 1. HTML needs to be strict and well formed 3. CSS is easy to read and fast 1. css("#logo-section a", "title") 28
  29. 29. © Gatling 2015.All rights reserved. Exercise 1: 3. Checks What happens when a check matches more than a single element? 1. exists by default 2. And, if you don’t specify a fetch method but try to save, Gatling will add a find(0) before saveAs 29
  30. 30. © Gatling 2015.All rights reserved. Exercise 1: 4. Information retrieval 30 Which check should you use to fetch the menu links ? 1. css("#main-menu-inner > ul > li > a", "href")
  31. 31. © Gatling 2015.All rights reserved. Exercise 1: 4. Information retrieval How can you save all matches? 1. findAll 31
  32. 32. © Gatling 2015.All rights reserved. Exercise 1: 4. Information retrieval How can you access the “menuLinks” attribute? 1. Use the exec { session => … } syntax 2. session(“menuLinks”) for extraction 3. Then, either 1. as[Type] 2. asOption[Type] 3. validate[Type] 4. Validate recommended unless you know what you are doing 32
  33. 33. © Gatling 2015.All rights reserved. Exercise 1: 4. Iterate over menu links Which DSL element should you use? 1. foreach 2. Takes an Expression[String] as its first argument 1. Which is a function of Session toValidation[String] 3. Gatling does the EL conversion for you 33
  34. 34. © Gatling 2015.All rights reserved. Exercise 1: 4. Iterate over menu links How do think it works behind the hood? 1. Iterate over each element 2. Put current element into the session as an attribute 3. Run the action block with the new session 34
  35. 35. © Gatling 2015.All rights reserved. Exercise 2: 1. Fetch the login page Which baseURL should you use? 1. Gatling doesn’t add a / before concatenating 2. One of the following 1. baseURL(“https://github.com”) and get(“/login”) 2. baseURL(“https://github.com/“) and get(“login”) 3. Prefer the first one 35
  36. 36. © Gatling 2015.All rights reserved. Exercise 2: 1. Fetch the login page Which check should you use? 1. The general idea is to make sure you are on the page you requested 2. css(".auth-form form h1").is("Sign in") 36
  37. 37. © Gatling 2015.All rights reserved. Exercise 2: 2.1. Performing the login Which request should you do? 1. /session Which HTTP method does it need to use? 2. POST 37
  38. 38. © Gatling 2015.All rights reserved. Exercise 2: 2.2. Specifying additional parameters Do you think these are generated or provided? 1. Generated by Github, provided in the HTML. Where can you fetch thoses? 2. Add a check to the previous request 3. css(".auth-form form input[name='authenticity_token']", “value").saveAs("authenticityToken") 38
  39. 39. © Gatling 2015.All rights reserved. Exercise 2: 3. Checks Which checks should you use to be sure you are logged in? 1. Check for content, titles, css, etc. 2. css(“.logged_in”) 3. exists is a default 39
  40. 40. © Gatling 2015.All rights reserved. Exercise 2: 4. Feeding the credentials Which feeder file format could you use? 1. Multiple formats are handled by Gatling 1. CSV,TSV, etc. 2. Just beware of malformed files 40
  41. 41. © Gatling 2015.All rights reserved. Exercise 2: 4. Feeding the credentials How does the session interact with the feeder? 1. A feeder outputs lines of CSV (and else) files into the session 2. One line per user, with different methods of retrieval 1. Queue, failure when reading is over 2. Random 3. Shuffle, which is a shuffle + queue 4. Circular 3. If you want more, you can skip the feeding to Gatling and fetch the records yourself 41
  42. 42. © Gatling 2015.All rights reserved. Exercise 3: 1. Create gist Think of multiple ways to load the templates 1. StringBody 2. RawFileBody 3. ELFileBody, with parsed content 42
  43. 43. © Gatling 2015.All rights reserved. Exercise 3: 1. Create gist Which one is better in this case? 1. All are good 2. Still, scala can handle string template pretty well 3. => StringBody 43
  44. 44. © Gatling 2015.All rights reserved. Exercise 4: Part 1. 1. Start simple Is using java.util.Random a good idea in this case? What could happen if you do? 1. Random is synchronized 2. Multiples threads would block each other when fetching 3. ThreadLocalRandom is not 4. It creates a single Random for eachThread, resolving conflicts 44
  45. 45. © Gatling 2015.All rights reserved. Exercise 4: Part 1. 4.A twist How does Gatling execute requests? 1. Each requests are launched in sequence 2. They cannot overlap 3. And cannot be launched asynchronously How should we proceed instead? 45
  46. 46. © Gatling 2015.All rights reserved. Exercise 4: Part 1. 4.A twist How does Gatling execute requests? 1. Each requests are launched in sequence 2. They cannot overlap 3. And cannot be launched asynchronously How should we proceed instead? 4. We can use the resources mechanism 5. Not its purpose, but it will work 46
  47. 47. © Gatling 2015.All rights reserved. Exercise 4: Part 1I. 2. Making the queries Is the number of tiles requested really fixed? 1. What about edges ? 2. Will reduce the number of tiles 3. We can reduce the bounds, excluding the edges 47
  48. 48. © Gatling 2015.All rights reserved. Exercise 4: Part 1I. 2. Making the queries Mixing Gatling’s EL and Scala’s String Macro 1. This a Gatling EL:“${variableName}” 2. Theses are Scala Macros: 1. s”$variableName” 2. s”${variableName} How? 48
  49. 49. © Gatling 2015.All rights reserved. Exercise 4: Part 1I. 2. Making the queries Mixing Gatling’s EL and Scala’s String Macro 1. This a Gatling EL:“${variableName}” 2. Theses are Scala Macros: 1. s”$variableName” 2. s”${variableName} How? 1. Escape Gatling’s EL when in a Scala String Macro 1. s”$${gatlingVariable}/${otherVariable}” 2. will output “${gatlingVariable}/variableContent” 49
  50. 50. © Gatling 2015.All rights reserved. Workshop Solutions 1. Not available yet Url bit.ly/gatling-workshop-solutions 50
  51. 51. © Gatling 2015.All rights reserved.
  52. 52. © Gatling 2015.All rights reserved. http://gatling.io http://github.com/gatling/gatling @GatlingTool

×