Gatling @ Scala.Io 2013

5,109 views

Published on

Gatling

0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,109
On SlideShare
0
From Embeds
0
Number of Embeds
78
Actions
Shares
0
Downloads
69
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Gatling @ Scala.Io 2013

  1. 1. Gatling 2, What’s up Doc? by Stéphane Landelle @slandelle
  2. 2. Quick Introduction / Reminder about
  3. 3. What’s Gatling? •  Stress Test Tool •  Scala + Akka +Netty •  Scenarios = code + DSL
  4. 4. Scenario val scn = scenario("Scala.Io DoS") .repeat(10000) { exec(http("Scala.Io").get("http://scala.io")) } setUp( scn.inject(rampUsers(10000) over 30 seconds) )
  5. 5. Scenario = Actor Workflow Start Actor Http Request Actor Session Repeat Actor End Actor Async Handler Actor
  6. 6. Scenario = Actor Workflow Start Actor Repeat Actor End Actor Session Http Request Actor Async Handler Actor
  7. 7. Scenario = Actor Workflow Start Actor Repeat Actor End Actor Session Http Request Actor Async Handler Async Handler Actor
  8. 8. Scenario = Actor Workflow Start Actor Http Request Actor End Actor Repeat Actor Session Async Handler Async Handler Actor
  9. 9. Scenario = Actor Workflow Start Actor End Actor Repeat Actor Session Http Request Actor Async Handler Actor
  10. 10. Scenario = Actor Workflow Start Actor Http Request Actor Session Repeat Actor End Actor Async Handler Actor
  11. 11. Timeline •  Mid 2011: o  Start developing Gatling o  No Scala background •  End 2012: o  Better Scala skills o  Community feedback o  Need for open APIs Time to clean this up!
  12. 12. Gatling 2! •  Planned for 2014: o  Tons of refactoring o  Tons of new features •  Sorry folks, we’re late: o  Greater good: stability •  Milestones: o  Current M3 o  Next M4 november/december
  13. 13. New Expression API
  14. 14. Expression in Gatling 1 type Expression = Session => String implicit def toExpression(s: String): Expression http("Foo").get("https://www.google.fr/search?q=${term}")
  15. 15. Gatling 1 issues o  What if “term” is undefined? o  What if “term” is of wrong type? repeat("${times}") {} // Expects Int foreach("${seq}”) {} // Expects Seq è Unsafe, deal with Exceptions, not generic
  16. 16. Validation Validation[+T] -  map -  flatMap Success[+T] (value: T) Failure (message: String)
  17. 17. Usage: Building a request flatMap that s**t! buildURI(httpAttributes.urlOrURI) .flatMap(configureQueryCookiesAndProxy) .flatMap(configureVirtualHost) .flatMap(configureHeaders) .flatMap(configureRealm)
  18. 18. New Expression API type Expression[T] = Session => Validation[T] implicit def toExpression[T](s: String): Expression[T]
  19. 19. New Session API val foo: Validation[T] = session("foo").validate[T] // unsafe: val bar: T = session("foo").as[T] val baz: Option[T] = session("foo").asOption[T]
  20. 20. New Templating API
  21. 21. Templating API in Gatling 1 •  (Session => String) / Expression: o  Function o  Implicitly compiled EL String •  Scalate SSP
  22. 22. Scalate SSP o  Can have complex logic o  Scala compiler in the background (overhead, proper stop) o  Own API, learning curve o  Does play well with Session API Why do we need this anyway?
  23. 23. New Templating API: the EL way Embedded // passing an EL String setBody(StringBody("""{ foo: "${foo}", bar: ${bar} }""")
  24. 24. New Templating API: the EL way External EL based text file // passing an EL File setBody(ELFileBody("body.txt")) { foo: "${foo}", bar: ${bar} }
  25. 25. New Templating API: the EL way o  Simple o  Limited, can’t implement complex logic
  26. 26. Why do we need non-Scala templates anyway?! We’re not in JSP world! We have multiline Strings and macros!
  27. 27. String interpolation val jsonTemplate: Expression[String] = session => for { foo <- session("foo").validate[String] bar <- session("bar").validate[Int] } yield s"""{ foo: "$foo", bar: $bar }"""
  28. 28. String interpolation o  Pure Scala o  Compile time, not runtime o  Standard Scala library o  Requires a bit more Scala skills o  Complex logic => intermediate String concatenations
  29. 29. Fastring https://github.com/Atry/fastring •  StringBuilder underneath •  Produces Fastrings, not Strings
  30. 30. Fastring val jsonTemplate: Expression[String] = session => for (foos <- session("foos").validate[Seq[String]]) yield fast"""{ foos = [ ${foos.map(foo => fast"""{foo: "$foo"}""").mkFastring("n")} ] }""".toString
  31. 31. Checks improvements
  32. 32. Regex check in Gatling 1 regex("foo(.*)bar").saveAs("baz") è produces Strings è no more than 1 capture group
  33. 33. Issue <form> <input type="hidden" name="foo" value="foo" /> <input type="hidden" name="bar" value="baz" /> </form> è workaround: 2 regex + manual zip
  34. 34. Tuple support We need: String (String, String) (String, String, String) (String, String, String, String) … But generic, please…
  35. 35. Type class FTW regex[T](pattern: Expression[String]) (implicit groupExtractor: GroupExtractor[T]) object GroupExtractor { implicit val groupExtractor2: GroupExtractor[(String, String)] = ??? } trait GroupExtractor regex[(String, String)]("foo(.*)bar(.*)baz")
  36. 36. Also for •  headerRegex[T] T of String, Tuple2[String] , Tuple3[String]… •  jsonPath[T] T of Int, Long, Double, Float, String, List, Map •  XPath? •  CSS selectors?
  37. 37. Resource fetching
  38. 38. Gatling 1 HTML page Resource 1 Resource 2 Sequential workflow Resource 3
  39. 39. Not how browsers work Resource 1 HTML page Resource 2 Resource 3 Parallel workflow
  40. 40. Very complex actually 1. Fetch HTML 2. Fetch HTML embedded resources 3. Fetch some additional resources (CSS @import) 4. Fetch matching CSS rules resources (@font-face, background-image) 5. … (not accounting for javascript) è Can’t be perfect without being a browser è Will have to approximate
  41. 41. Kind of scatter-gather pattern Fetch resources HTML page Session + HTML Resource Fetcher Actor New Session Beware of Session reconciliation! Next
  42. 42. DSL exec( http(“Page").get("http://foo.com") .resources( http(“Ajax1").get("http://foo.com/ajax1"), http(“Ajax2").get("http://foo.com/ajax2") .check(regex("foo(.*)bar").saveAs("baz")) ) )
  43. 43. And many more to come… Q/A? @GatlingTool http://gatling-tool.org https://github.com/excilys/gatling

×