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

はじめての Gatling

Avatar for n0ts n0ts
August 19, 2016

はじめての Gatling

Avatar for n0ts

n0ts

August 19, 2016
Tweet

More Decks by n0ts

Other Decks in Technology

Transcript

  1. ໨࣍ • Gatling ͱ͸ • Gatling ͷΠϯετʔϧํ๏ • Gatling Ϩίʔμʔ

    • Gatling ͷ࢖͍ํ • Gatling ͷϨϙʔτ • Gatling ͷ࣮ྫ Tips
  2. Gatling ͱ͸ • http://gatling.io • Scala ϕʔεͷߴෛՙςετϑϨʔϜϫʔΫ • ab ΍

    wrk ͷΑ͏ͳϕϯνϚʔΫʹ͍͕ۙɺScala Ͱϩ δοΫΛهड़͢Δ͜ͱ͕Ͱ͖Δ • ab (Apache Bench): • https://httpd.apache.org/docs/2.4/programs/ ab.html • wrk: • https://github.com/wg/wrk
  3. ಛ௕ • HTML ϨϙʔτͰग़ྗ͢Δ͜ͱ͕Ͱ͖Δ • HTTP GET Ҏ֎ʹ΋ POST ʹ΋ରԠ͍ͯ͠Δ

    • ϦϑΝϥʔɺΫοΩʔͷ෇༩͸σϑΥϧτͰରԠ͍ͯ͠ Δʂ • Scala ྗ͕௿ͯ͘΋Ҏ֎ͱ؆୯ʹઃఆΛॻ͘͜ͱ͕ग़དྷ Δʢࣗݧʂʣ
  4. ϨίʔμʔͰੜ੒͞ΕΔγφϦΦͷྫ package computerdatabase // ύοέʔδ໊ import io.gatling.core.Predef._ // ඞཁͳΠϯϙʔτͨͪ import

    io.gatling.http.Predef._ import scala.concurrent.duration._ class BasicSimulation extends Simulation { // ΫϥεఆٛɺSimulation Λܟশ͠ͳ͍ͱ͍͚ͳ͍ val httpConf = http // HTTP ϦΫΤετͷڞ௨ઃఆ .baseURL("http://computer-database.gatling.io") // ϦΫΤετର৅ͷ URL .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // ڞ௨ͷ HTTP ϔομʔ .doNotTrackHeader("1") // DNT ϔομʔͷૹ৴ .acceptLanguageHeader("en-US,en;q=0.5") // ड͚ೖΕΔݴޠϔομʔͷૹ৴ .acceptEncodingHeader("gzip, deflate") // ΤϯίʔσΟϯάϔομʔͷૹ৴ .userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0") // ϢʔβΤʔδΣϯτͷૹ৴ val scn = scenario("BasicSimulation") // ςετγφϦΦͷఆٛ .exec(http("request_1") // HTTP ϦΫΤετ໊ɺ"request_1" ͸࠷ऴϨϙʔτʹදࣔ͞ΕΔ .get("/")) // URI / ΁ GET ϦΫΤετ͢Δ .pause(5) // Ұ࣌εϦʔϓλΠϜ setUp( // ͜ͷγϛϡϨʔγϣϯͰ࣮ߦ͢ΔγφϦΦͷηοτΞοϓ scn.inject(atOnceUsers(1)) // scn ͱ͍͏໊લͰ 1 γϯάϧϢʔβͰϦΫΤετ͢Δ ).protocols(httpConf) // ࠷ॳͷ HTTP ϦΫΤετͷڞ௨ઃఆΛ෇༩͢Δ }
  5. ࣮ߦྫ $ bin/gatling.sh GATLING_HOME is set to $GATLING_ROOT Choose a

    simulation number: [0] test.BasicSimulation [1] test.FooSimulation ※番号を入力 1 ... ---- Global Information -------------------------------------------------------- > request count 10 (OK=10 KO=0 ) > min response time 5 (OK=5 KO=- ) > max response time 58 (OK=58 KO=- ) > mean response time 16 (OK=16 KO=- ) > std deviation 14 (OK=14 KO=- ) > response time 50th percentile 12 (OK=12 KO=- ) > response time 75th percentile 17 (OK=17 KO=- ) > mean requests/sec 5.141 (OK=5.141 KO=- ) *1 ---- Response Time Distribution ------------------------------------------------ > t < 800 ms 10 (100%) > 800 ms < t < 1200 ms 0 ( 0%) > t > 1200 ms 0 ( 0%) > failed 0 ( 0%) ================================================================================ Reports generated in 0s. Please open the following file: results/scenariosimulation-xxx/index.html *1: ඵؒ͋ͨΓͷॲཧͨ͠ΓΫΤετ਺ɺKO ͸ NG ͱ͍͏ҙຯ
  6. ͋Δ৚݅ͷͱ͖ͷΈϦΫΤετΛ͢Δ • scenarioProperty ͕ pv ͷͱ͖ϦΫΤετΛ͢Δ val scenarioProperty = System.getProperty("scenario",

    "").toString
 val scn = scenario("DoIfBenchmark") .doIf(scenarioProperty, "pv") { exec(http("pv").get("/pv")) }
  7. ͋Δׂ߹͝ͱʹϦΫΤετΛ͢Δ • / Λ 50%ɺ/foo Λ 20%ɺ/bar Λ 30% ͣͭϦΫΤετ

    ͢Δ val scn = scenario("RandomBenchmark")
 .randomSwitch( 50.0 -> exec(http("top").get("/")), 20.0 -> exec(http("foo").get("/foo")), 30.0 -> exec(http("bar").get("/bar")) )
  8. ϦΫΤετʹಈతʹΫοΩʔΛ෇༩͢Δ • / ͷΫοΩʔ uid Λ /cookie ΁෇༩͢Δ val scn

    = scenario("CookieBenchmark")
 .exec(http("top") .get("/") .check(headerRegex("Set-Cookie", "uid=(.*); Expires=.*; Domain=.*; Path=.*").saveAs("uid"))) .exec(addCookie(Cookie("uid", "${uid}"))) .exec(http("cookie").get("/"))
  9. ϦΫΤετʹಈతʹ UA Λมߋ͢Δ • /baz ΁ͷϦΫΤετ͸ "bar UA" ʹ͢Δ val

    userAgent = Map("User-Agent" -> "bar UA") val scn = scenario("UABenchmark")
 .exec(http("baz") .get("/baz") .headers(userAgent) )
  10. εςʔλείʔυ 303 ͸εςʔλε OK ͱ͢Δ • /redirect ͸ 303 Λฦͯ͠ɺϦμΠϨΫτ͸͠ͳ͍

    val scn = scenario("RedirectBenchmark")
 .exec(http("top") .get("/redirect") .disableFollowRedirect .check(status.is(303)) )
  11. 2.2 Ͱͷมߋ఺ - JDK & Core • JDK8 ͕ඞਢʹͳΓ·ͨ͠ʢσϑΥϧτ͸ G1

    GCʣ • FeederʢIterator[Map[String, T]] ͷΤΠϦΞεʣίϯςϯπʹ ରͯ͠ shuffle Ͱ͖ΔΑ͏ʹͳΓ·ͨ͠ http://gatling.io/docs/ 2.2.2/session/feeder.html#feeder • AsssertionʢϨεϙϯελΠϜ΍ࣦഊͨ͠ϦΫΤετʹରͯ͠Ͳ ͷ͘Β͍ڐ༰͢Δ͔ઃఆ͢Δ΋ͷʣʹ per-million ͕αϙʔτ͞ Εͨ • 2.2.1 ͔Βɺ͋Δ৚݅Λຬ͍ͨͯ͠Δͱ͖࣮ߦ͢Δػߏ Conditional Checking ͕αϙʔτ͞Εͨ
  12. 2.2 Ͱͷมߋ఺ - HTTP • Netty 4 ϕʔεͰ࠶࣮૷͞Εͨʢͨͩ͠ Linux ্ͰͷΈར༻Մೳʣ

    • OpenSSL ͱ BoringSSL(Google's fork) ͕αϙʔτ͞Εͨ • HTML ϑΥʔϜͰೖྗΛΩϟϓνϟʔͯ͠ɺͦͷ݁ՌΛ֬ೝͰ͖ ΔΑ͏ʹͳͬͨ • form("cssSelector").saveAs("myForm") • HTTP ϙʔϦϯά͕αϙʔτ͞Εͨ • exec(polling.every(10 seconds).exec(http("name").get("url"))) • exec(polling.stop) • ϗετ໊ͷΤΠϦΞε͕Մೳʹͳͬͨ • ෳ਺ͷϩʔΧϧΞυϨεʹରͯ͠ϦΫΤετͰ͖ΔΑ͏ʹͳͬͨ