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. Scenario = Actor Workflow
Start
Actor
Http Request
Actor
Session
Repeat
Actor
End
Actor
Async Handler
Actor
6. Scenario = Actor Workflow
Start
Actor
Repeat
Actor
End
Actor
Session
Http Request
Actor
Async Handler
Actor
7. Scenario = Actor Workflow
Start
Actor
Repeat
Actor
End
Actor
Session
Http Request
Actor
Async
Handler
Async Handler
Actor
8. Scenario = Actor Workflow
Start
Actor
Http Request
Actor
End
Actor
Repeat
Actor
Session
Async
Handler
Async Handler
Actor
9. Scenario = Actor Workflow
Start
Actor
End
Actor
Repeat
Actor
Session
Http Request
Actor
Async Handler
Actor
10. Scenario = Actor Workflow
Start
Actor
Http Request
Actor
Session
Repeat
Actor
End
Actor
Async Handler
Actor
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. 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
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. 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
17. Usage: Building a request
flatMap that s**t!
buildURI(httpAttributes.urlOrURI)
.flatMap(configureQueryCookiesAndProxy)
.flatMap(configureVirtualHost)
.flatMap(configureHeaders)
.flatMap(configureRealm)
18. New Expression API
type Expression[T] = Session => Validation[T]
implicit def toExpression[T](s: String): Expression[T]
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]
21. Templating API in Gatling 1
• (Session => String) / Expression:
o Function
o Implicitly compiled EL String
• Scalate SSP
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. New Templating API: the EL way
Embedded
// passing an EL String
setBody(StringBody("""{
foo: "${foo}",
bar: ${bar}
}""")
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. New Templating API: the EL way
o Simple
o Limited, can’t implement complex logic
26. Why do we need
non-Scala templates anyway?!
We’re not in JSP world!
We have multiline Strings and macros!
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. 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
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. 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?
39. Not how browsers work
Resource
1
HTML
page
Resource
2
Resource
3
Parallel workflow
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. Kind of scatter-gather pattern
Fetch
resources
HTML
page
Session
+ HTML
Resource
Fetcher
Actor
New
Session
Beware of Session reconciliation!
Next