Upgrade to Pro — share decks privately, control downloads, hide ads and more …

My Gatling gun tears your meat Grinder apart

My Gatling gun tears your meat Grinder apart

Your customer needs to load test their API but you're short on time and have to deliver some numbers within a week. Ah, and you've never done any load testing before. What do you do?

Jan Fredrik Wedén

December 04, 2012
Tweet

More Decks by Jan Fredrik Wedén

Other Decks in Programming

Transcript

  1. MY GATLING GUN TEARS YOUR MEAT GRINDER APART A novice’s

    first exposure to load testing javaBin julemøte Trondheim Jan Fredrik Wedén 2012
  2. I can haz load test in a week kthxbye (Help!)

    We have a SOAP service Mission:
  3. Factor The Grinder Gatling Well-known +++ - Maturity +++ +

    Getting started ++ +++ Buzzwords + +++++
  4. Factor The Grinder Gatling Well-known +++ - Maturity +++ +

    Getting started ++ +++ Buzzwords + +++++ Gut feeling +++ +
  5. Factor The Grinder Gatling Well-known +++ - Maturity +++ +

    Getting started ++ +++ Buzzwords + +++++ Gut feeling +++ + DG1 12 10
  6. def createRequest(test, url, headers): request = HTTPRequest(url=url) if headers: request.headers=headers

    test.record(request, HTTPRequest.getHttpMethodFilter()) return request request101 = createRequest(Test(101, 'POST getCustomers'), URL, globalHeaders) class TestRunner: def getCustomersRequest(self, username): result = request101.POST(URL, “bar”, headers) def __call__(self): self.getCustomersRequest() Test(100, 'getCustomers').record(TestRunner.getCustomersRequest) The Grinder
  7. Class APISimulation extends Simulation { def apply = { val

    myScenario = scenario(”Customers scenario") .exec(http("getCustomers") .post(URL) .header("Content-Type", ""”foo""") .body(”bar”) ) List(myScenario.configure.users(10).ramp(20).protocolConfig(httpConf)) } } Gatling
  8. users = [] usersfile = open("./users.txt", "r") for line in

    usersfile.readlines(): if not line.startswith('#'): users.append(line.strip().split(',')) usersfile.close() … (uidToUse, pwdToUse) = users[grinder.threadNumber % len(users)] The Grinder
  9. Factor The Grinder Gatling Readability - +++ Scaffolding - +++

    Multiple users - +++ Extensibility +++ ++
  10. Factor The Grinder Gatling Readability - +++ Scaffolding - +++

    Multiple users - +++ Extensibility +++ ++ Reports ? +++
  11. Factor The Grinder Gatling Readability - +++ Scaffolding - +++

    Multiple users - +++ Extensibility +++ ++ Reports ? +++ Request body - +++
  12. template = open("./requesttemplates/getCustomers.xml") getCustomersTemplate = template.read() template.close() … def getCustomersRequest(self,

    username): customersMsg = getCustomersTemplate.replace("${uid}", username) result = request101.POST(URL, customersMsg, headers) The Grinder
  13. Factor The Grinder Gatling Readability - +++ Scaffolding - +++

    Multiple users - +++ Extensibility +++ ++ Reports ? +++ Request body - +++ Checks + +++
  14. contractNumExpression = re.compile(r"ContractNum>(\d*)</") … def getContractsRequest(self, username, securityKey): contractsMsg =

    getContractsTemplate.replace("${uid}", username) result = request301.POST(URL, contractsMsg, headers) if 'soap:Fault' in httpResponse.text: grinder.logger.debug(result.text) grinder.statistics.forCurrentTest.setSuccess(False) return result … contractsResponse = self.getContractsRequest(uidToUse, securityKey) contractMatch = contractNumExpression.search(contractsResponse.text) if contractMatch: contractNum = contractMatch.group(1) if contractMatch: self.getContractDetailRequest(uidToUse, securityKey, contractNum) The Grinder
  15. .exec(http("getContracts") .post(URL) .header("Content-Type", ""”blah""") .fileBody("getContracts", Map("uid" -> "${uid}”)) .check( status.is(200),

    regex("""soap:Fault""").notExists, regex("""ContractNum>(\d*)</""").whatever.saveAs("contractnum”) ) ) .doIf(session => session.isAttributeDefined("contractnum”)) { exec(http("getContractDetail") … } Gatling
  16. Factor The Grinder Gatling Readability - +++ Scaffolding - +++

    Multiple users - +++ Extensibility +++ ++ Reports ? +++ Request body - +++ Checks + +++ Scaling +++ +
  17. Factor The Grinder Gatling Readability - +++ Scaffolding - +++

    Multiple users - +++ Extensibility +++ ++ Reports ? +++ Request body - +++ Checks + +++ Scaling +++ + DG2 7 21
  18. Gatling may not tear The Grinder (completely) apart Conclusion: But

    it makes some serious dents and is my winner