gatling @ scala.io 2013

43
Gatling 2, What’s up Doc? by Stéphane Landelle @slandelle

Upload: slandelle

Post on 07-May-2015

3.456 views

Category:

Technology


1 download

DESCRIPTION

Gatling

TRANSCRIPT

Page 1: Gatling @ Scala.Io 2013

Gatling 2, What’s up Doc?

by Stéphane Landelle @slandelle

Page 2: Gatling @ Scala.Io 2013

Quick Introduction / Reminder about

Page 3: Gatling @ Scala.Io 2013

What’s Gatling?

• Stress Test Tool

• Scala + Akka +Netty

• Scenarios = code + DSL

Page 4: Gatling @ Scala.Io 2013

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) )

Page 5: Gatling @ Scala.Io 2013

Scenario = Actor Workflow

Repeat Actor

Start Actor

Http Request Actor

End Actor

Async Handler Actor

Session

Page 6: Gatling @ Scala.Io 2013

Scenario = Actor Workflow

Repeat Actor

Start Actor

Http Request Actor

End Actor

Async Handler Actor

Session

Page 7: Gatling @ Scala.Io 2013

Scenario = Actor Workflow

Repeat Actor

Start Actor

Http Request Actor

End Actor

Async Handler Actor

Async Handler

Session

Page 8: Gatling @ Scala.Io 2013

Scenario = Actor Workflow

Repeat Actor

Start Actor

Http Request Actor

End Actor

Async Handler Actor

Async Handler

Session

Page 9: Gatling @ Scala.Io 2013

Scenario = Actor Workflow

Repeat Actor

Start Actor

Http Request Actor

End Actor

Async Handler Actor

Session

Page 10: Gatling @ Scala.Io 2013

Scenario = Actor Workflow

Repeat Actor

Start Actor

Http Request Actor

End Actor

Async Handler Actor

Session

Page 11: Gatling @ Scala.Io 2013

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!

Page 12: Gatling @ Scala.Io 2013

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

Page 13: Gatling @ Scala.Io 2013

New Expression API

Page 14: Gatling @ Scala.Io 2013

Expression in Gatling 1

type Expression = Session => String implicit def toExpression(s: String): Expression http("Foo").get("https://www.google.fr/search?q=${term}")

Page 15: Gatling @ Scala.Io 2013

Gatling 1 issues o What if “term” is undefined? o What if “term” is of wrong type?

è Unsafe, deal with Exceptions, not generic

repeat("${times}") {} // Expects Int foreach("${seq}”) {} // Expects Seq

Page 16: Gatling @ Scala.Io 2013

Validation

Validation[+T] -  map -  flatMap

Success[+T] (value: T)

Failure (message: String)

Page 17: Gatling @ Scala.Io 2013

Usage: Building a request

flatMap that s**t!

buildURI(httpAttributes.urlOrURI) .flatMap(configureQueryCookiesAndProxy) .flatMap(configureVirtualHost) .flatMap(configureHeaders) .flatMap(configureRealm)

Page 18: Gatling @ Scala.Io 2013

New Expression API

type Expression[T] = Session => Validation[T] implicit def toExpression[T](s: String): Expression[T]

Page 19: Gatling @ Scala.Io 2013

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]

Page 20: Gatling @ Scala.Io 2013

New Templating API

Page 21: Gatling @ Scala.Io 2013

Templating API in Gatling 1

•  (Session => String) / Expression:

o  Function o  Implicitly compiled EL String

• Scalate SSP

Page 22: Gatling @ Scala.Io 2013

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?

Page 23: Gatling @ Scala.Io 2013

New Templating API: the EL way

Embedded

// passing an EL String setBody(StringBody("""{ foo: "${foo}", bar: ${bar} }""")

Page 24: Gatling @ Scala.Io 2013

New Templating API: the EL way

External EL based text file

// passing an EL File setBody(ELFileBody("body.txt"))

{ foo: "${foo}", bar: ${bar} }

Page 25: Gatling @ Scala.Io 2013

New Templating API: the EL way

o  Simple

o  Limited, can’t implement complex logic

Page 26: Gatling @ Scala.Io 2013

Why do we need non-Scala templates anyway?!

We’re not in JSP world!

We have multiline Strings and macros!

Page 27: Gatling @ Scala.Io 2013

String interpolation val jsonTemplate: Expression[String] = session => for { foo <- session("foo").validate[String] bar <- session("bar").validate[Int] } yield s"""{

foo: "$foo", bar: $bar }"""

Page 28: Gatling @ Scala.Io 2013

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

Page 29: Gatling @ Scala.Io 2013

Fastring

https://github.com/Atry/fastring •  StringBuilder underneath •  Produces Fastrings, not Strings

Page 30: Gatling @ Scala.Io 2013

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

Page 31: Gatling @ Scala.Io 2013

Checks improvements

Page 32: Gatling @ Scala.Io 2013

Regex check in Gatling 1

è produces Strings è no more than 1 capture group

regex("foo(.*)bar").saveAs("baz")

Page 33: Gatling @ Scala.Io 2013

Issue <form> <input type="hidden" name="foo" value="foo" /> <input type="hidden" name="bar" value="baz" /> </form>

è workaround: 2 regex + manual zip

Page 34: Gatling @ Scala.Io 2013

Tuple support We need:

String (String, String)

(String, String, String) (String, String, String, String)

But generic, please…

Page 35: Gatling @ Scala.Io 2013

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")

Page 36: Gatling @ Scala.Io 2013

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?

Page 37: Gatling @ Scala.Io 2013

Resource fetching

Page 38: Gatling @ Scala.Io 2013

Gatling 1

HTML page

Resource 1

Resource 2

Resource 3

Sequential workflow

Page 39: Gatling @ Scala.Io 2013

Not how browsers work

HTML page

Resource 1

Resource 2

Resource 3

Parallel workflow

Page 40: Gatling @ Scala.Io 2013

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

Page 41: Gatling @ Scala.Io 2013

Kind of scatter-gather pattern

HTML page

ResourceFetcher Actor

Beware of Session reconciliation!

Session + HTML

Fetch resources

New Session

Next

Page 42: Gatling @ Scala.Io 2013

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")) ) )

Page 43: Gatling @ Scala.Io 2013

And many more to come…

Q/A? @GatlingTool

http://gatling-tool.org

https://github.com/excilys/gatling