public
Last active

Benchmarks for Gatling: Gatling's simulation

  • Download Gist
gistfile1.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
val urlBase = "http://192.168.10.142:8080"
 
val httpConf = httpConfig.baseURL(urlBase)
 
val common_headers = Map(
"Accept-Charset" -> "ISO-8859-1,utf-8;q=0.7,*;q=0.3",
"Accept-Encoding" -> "gzip,deflate,sdch",
"Accept-Language" -> "en-US,en;q=0.8,fr;q=0.6",
"Host" -> "192.168.10.142:8080",
"User-Agent" -> "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.71 Safari/534.24")
 
val post_headers = Map(
"Content-Type" -> "application/x-www-form-urlencoded",
"Origin" -> "http://192.168.10.142:8080")
 
val ajax_headers = Map(
"Accept" -> "application/json, text/javascript, */*; q=0.01",
"X-Requested-With" -> "XMLHttpRequest")
 
val common_accept = ("Accept" -> "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5")
 
val cache_control_header = ("Cache-Control" -> "max-age=0")
 
val referer_login = ("Referer" -> "http://192.168.10.142:8080/excilys-bank-web/public/login.html")
 
val referer_operations = ("Referer" -> "http://192.168.10.142:8080/excilys-bank-web/private/bank/account/${acc1}/operations.html")
 
val referer_operations_transfer = ("Referer" -> "http://192.168.10.142:8080/excilys-bank-web/private/bank/account/${acc1}/transfers/operations.html")
 
val login_page_headers = common_headers + common_accept + cache_control_header
 
val authentication_headers = common_headers + common_accept + cache_control_header ++ post_headers + referer_login + ("Content-Length" -> "35")
 
val accounts_page_headers = common_headers + common_accept + cache_control_header + referer_login
 
val operations_headers = common_headers + common_accept + ("Referer" -> "http://192.168.10.142:8080/excilys-bank-web/private/bank/accounts.html")
 
val operations_data_headers = common_headers ++ ajax_headers + referer_operations
 
val cards_operations_headers = common_headers + common_accept + referer_operations
 
val cards_operations_data_headers = common_headers ++ ajax_headers + referer_operations_transfer
 
val transfer_viewing_headers = common_headers + common_accept + referer_operations_transfer
 
val perform_transfer_headers = common_headers + common_accept + cache_control_header ++ post_headers ++ Map(
"Referer" -> "http://192.168.10.142:8080/excilys-bank-web/private/bank/account/${acc1}/transfers/perform.html",
"Content-Length" -> "65")
 
val logout_headers = common_headers + common_accept + ("Referer" -> "http://192.168.10.142:8080/excilys-bank-web/private/bank/accounts.html?accountNumber=${acc1}&page=TRANSFER_PERFORM")
 
val scn = scenario("Test Gatling vs JMeter")
.feed(tsv("bank_users.tsv").random)
.exec(
http("Authentication page before login")
.get("/excilys-bank-web/public/login.html")
.headers(login_page_headers)
.check(regex("""<legend>Please log in</legend>""")))
.pause(5)
.exec(
http("Authentication")
.post("/excilys-bank-web/login")
.param("username", "${username}")
.param("password", "${password}")
.headers(authentication_headers)
.check(status.eq(302)))
.loop(
chain
.pause(100, MILLISECONDS)
.exec(
http("Accounts")
.get("/excilys-bank-web/private/bank/accounts.html")
.headers(accounts_page_headers)
.check(
regex("""<a href="/excilys-bank-web/private/bank/account/(ACC[0-9]*)/operations.html">""").find(0).saveAs("acc1"),
regex("""<a href="/excilys-bank-web/private/bank/account/(ACC[0-9]*)/operations.html">""").find(1).saveAs("acc2")))
.pause(5)
.exec(
http("Operations")
.get("/excilys-bank-web/private/bank/account/${acc1}/operations.html")
.headers(operations_headers)
.check(regex("""<td class="amount"><span class="figure green">(.*)</span>""")))
.pause(100, MILLISECONDS)
.exec(
http("Operations data")
.get("/excilys-bank-web/private/bank/account/${acc1}/year/2011/month/12/page/0/operations.json")
.headers(operations_data_headers))
.pause(5)
.exec(
http("Cards operations")
.get("/excilys-bank-web/private/bank/account/${acc1}/cards/all/operations.html")
.headers(cards_operations_headers))
.pause(100, MILLISECONDS)
.exec(
http("Cards operations data")
.get("/excilys-bank-web/private/bank/account/${acc1}/cards/all/year/2011/month/12/page/0/operations.json")
.headers(cards_operations_data_headers))
.pause(5)
.exec(
http("Transfers operations")
.get("/excilys-bank-web/private/bank/account/${acc1}/transfers/operations.html")
.headers(transfer_viewing_headers)
.check(regex("""<a href="/excilys-bank-web/private/bank/account/${acc1}/transfers/perform.html">""")))
.pause(100, MILLISECONDS)
.exec(
http("Transfers operations data")
.get("/excilys-bank-web/private/bank/account/${acc1}/transfers/page/0/operations.json")
.headers(transfer_viewing_headers))
.pause(5)
.exec(
http("Perform transfer")
.get("/excilys-bank-web/private/bank/account/${acc1}/transfers/perform.html")
.headers(transfer_viewing_headers)
.check(regex("""<legend>Perform a new transfer</legend>""")))
.pause(5)
.exec(
http("Performing transfer")
.post("/excilys-bank-web/private/bank/account/${acc1}/transfers/perform.html")
.param("debitedAccountNumber", "${acc1}")
.param("creditedAccountNumber", "${acc2}")
.param("amount", "100")
.headers(perform_transfer_headers)
.check(status.eq(302)))).times(20)
.pause(5)
.exec(
http("Logout")
.get("/excilys-bank-web/logout")
.headers(logout_headers)
.check(status.eq(302)))
.pause(100, MILLISECONDS)
.exec(
http("Authentication page after logout")
.get("/excilys-bank-web/public/login.html")
.headers(logout_headers)
.check(regex("""<legend>Please log in</legend>""")))
 
runSimulation(
scn.configure users (2000) ramp (200) protocolConfig httpConf)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.