Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
はじめての Gatling
Search
n0ts
August 19, 2016
Technology
66
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
はじめての Gatling
n0ts
August 19, 2016
More Decks by n0ts
See All by n0ts
MySQL Casual Talks Vol.3 〜カジュアルだよこわくないよ〜
n0ts
2
100
Other Decks in Technology
See All in Technology
コーチングの奥義 何もしないテクニック
jinwatanabe
0
140
AI・HPC開発を支えるGPU環境の新しい選択肢 液冷GPUシステム「AquSys」の取り組み
gpuunite_official
0
210
20分でわかるセキュアAPI
nwiizo
2
320
AIで変わるエンジニアの働き方(仮)
naoinaoi
0
310
Sets in Go
ramalho
1
1.2k
Kiro入門|仕様駆動開発で変わるAI時代の開発スタイル
cmkudo
0
300
暗号化?某ファイルストレージはどうなるの!? 3rd Partyとうまく付き合う秘密度ラベル設計
kasada
0
110
Model Studio CLI × Token Plan
maigo999
0
200
Adding Right-to-Left support to your web application with CSS logical properties — Lessons from Redmine
vividtone
0
160
LLM Internals: 언어 모델의 계보와 알고리즘 진화 (2023~2026)
inureyes
PRO
1
850
Android skills に学ぶ
kokiko
0
140
AI時代のアウトプット――変わったこと、変わらないこと / Devsumi 2026 Kansai #devsumi
jnchito
0
480
Featured
See All Featured
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Being A Developer After 40
akosma
91
590k
The Pragmatic Product Professional
lauravandoore
37
7.4k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
420
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
340
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
It's Worth the Effort
3n
188
29k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.5k
Abbi's Birthday
coloredviolet
3
9.4k
Transcript
͡Ίͯͷ Gatling Naoya Nakazawa @n0ts 2016/08/19
࣍ • Gatling ͱ • Gatling ͷΠϯετʔϧํ๏ • Gatling Ϩίʔμʔ
• Gatling ͷ͍ํ • Gatling ͷϨϙʔτ • Gatling ͷ࣮ྫ Tips
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
ಛ • HTML ϨϙʔτͰग़ྗ͢Δ͜ͱ͕Ͱ͖Δ • HTTP GET Ҏ֎ʹ POST ʹରԠ͍ͯ͠Δ
• ϦϑΝϥʔɺΫοΩʔͷ༩σϑΥϧτͰରԠ͍ͯ͠ Δʂ • Scala ྗ͕ͯ͘Ҏ֎ͱ؆୯ʹઃఆΛॻ͘͜ͱ͕ग़དྷ Δʢࣗݧʂʣ
Πϯετʔϧ 1. JDK8 Ҏ͕߱ඞཁͳͷͰɺΠϯετʔϧ 2. ެࣜϗʔϜϖʔδ͔Β zip ϑΝΠϧΛμϯϩʔυ http://gatling.io/#/download 3.
Linux / OS X ͳΒ bin/gatling.sh ͋Δ͍ɺWindows ͳΒ bin/gatling.bat Ͱ࣮ߦ͢Δ͚ͩ
Ϩίʔμʔ • Gatling ͷςετγφϦΦΛࣗಈతʹੜ͢Δπʔϧ • bin/recorder.sh Ͱ࣮ߦ͢Δ • ϨίʔμʔͰ։࢝͢ΔͱɺϓϩΩγܦ༝ͷϦΫΤετ ͕ࣗಈతʹ
Gatling ͷγϛϡϨʔγϣϯϑΝΠϧͱ͠ ͯอଘ͞ΕΔ
Ϩίʔμʔը໘
ϨίʔμʔͰੜ͞ΕΔγφϦΦͷྫ 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 ϦΫΤετͷڞ௨ઃఆΛ༩͢Δ }
࣮ߦྫ $ 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 ͱ͍͏ҙຯ
࣮ߦ݁Ռ • ͋Θͤͯ results ҎԼʹ HTML ϑΝΠϧͱͯ͠ग़ྗ͞Ε Δ http://gatling.io/docs/2.2.2/general/reports.html
Gatling ͷ࣮ྫ
ಉ͡ϦΫΤετΛ܁Γฦ͢ • 5 ճ࿈ଓͰ܁Γฦ͢ val scn = scenario("RepeatBenchmark") .repeat(5, "n")
{ exec(http("top").get("/")) }
͋Δ݅ͷͱ͖ͷΈϦΫΤετΛ͢Δ • scenarioProperty ͕ pv ͷͱ͖ϦΫΤετΛ͢Δ val scenarioProperty = System.getProperty("scenario",
"").toString val scn = scenario("DoIfBenchmark") .doIf(scenarioProperty, "pv") { exec(http("pv").get("/pv")) }
͋Δׂ߹͝ͱʹϦΫΤετΛ͢Δ • / Λ 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")) )
ϦΫΤετʹಈతʹΫοΩʔΛ༩͢Δ • / ͷΫοΩʔ 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("/"))
ϦΫΤετʹಈతʹ UA Λมߋ͢Δ • /baz ͷϦΫΤετ "bar UA" ʹ͢Δ val
userAgent = Map("User-Agent" -> "bar UA") val scn = scenario("UABenchmark") .exec(http("baz") .get("/baz") .headers(userAgent) )
εςʔλείʔυ 303 εςʔλε OK ͱ͢Δ • /redirect 303 Λฦͯ͠ɺϦμΠϨΫτ͠ͳ͍
val scn = scenario("RedirectBenchmark") .exec(http("top") .get("/redirect") .disableFollowRedirect .check(status.is(303)) )
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 ͕αϙʔτ͞Εͨ
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) • ϗετ໊ͷΤΠϦΞε͕Մೳʹͳͬͨ • ෳͷϩʔΧϧΞυϨεʹରͯ͠ϦΫΤετͰ͖ΔΑ͏ʹͳͬͨ
2.2 Ͱͷมߋ - Reports • JUnit ͷϑΥʔϚοτϨϙʔτ͕αϙʔτ͞Εͨ • ࣄલʹઃఆͨ͠άϧʔϓ͝ͱʹϨϙʔτΛੜͰ͖ΔΑ ͏ʹͳͬͨ
• Maven ϓϥάΠϯ͕ test ͱ integration-test ͕αϙʔ τ͞Εͨ
͜ͷଞެࣜυΩϡϝϯτΛͲ͏ͧ http://gatling.io/docs/2.2.2/general/ index.html
Enjoy!!!