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
GAE/Go の勘どころ
Search
Osamu TONOMORI
April 27, 2017
Programming
10
4.9k
GAE/Go の勘どころ
golang.tokyo #5
Osamu TONOMORI
April 27, 2017
Tweet
Share
More Decks by Osamu TONOMORI
See All by Osamu TONOMORI
About Merpay Architect Team 2021
osamingo
0
1.6k
Gopher's Travel Journal 2018
osamingo
1
1.8k
Go のライブラリやっていき 💪 #go #golang / Let's creating a original library by Go
osamingo
3
1.9k
Google App Engine を利用した、新規 Web サービスの立ち上げ方
osamingo
23
8.2k
Go で始める JSON-RPC 入門
osamingo
4
54k
Other Decks in Programming
See All in Programming
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
200
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
役立つログに取り組もう
irof
28
9.6k
CSC509 Lecture 13
javiergs
PRO
0
110
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
Amazon Qを使ってIaCを触ろう!
maruto
0
410
Featured
See All Featured
Site-Speed That Sticks
csswizardry
0
28
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Happy Clients
brianwarren
98
6.7k
Faster Mobile Websites
deanohume
305
30k
A better future with KSS
kneath
238
17k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Building Adaptive Systems
keathley
38
2.3k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Transcript
GAE/Go ͷצͲ͜Ζ @osamingo golang.tokyo #5 (2017/04/27)
The golang.tokyo logo was made by Takuya Ueda. The Go
gopher was designed by Renee French.
Agenda 1. ࣗݾհ 2. GAE ʹ͍ͭͯ 3. GAE ্Ͱͷ Go
app ͷצͲ͜Ζ 4. ӡ༻͢Δͱ͖ͷ Tips 5. ·ͱΊ 3
Agenda 1. ࣗݾհ 2. GAE ʹ͍ͭͯ 3. GAE ্Ͱͷ Go
app ͷצͲ͜Ζ 4. ӡ༻͢Δͱ͖ͷ Tips 5. ·ͱΊ 4
ࣗݾհ
ۭલઈޙͷ͓͓͓͒ʂʂौ୩/ຊ ʹੜଉ͍ͯ͠ΔΰΥΥϑΝΝΝΝ 㷉ˑϖˑ㷊ʂʂʂ৽ن։ൃΛѪ͠ɺ ৽ن։ൃʹѪ͞Ε͓ͨͱ͒͜ʔʂʂ
;͚ͯ͟ɺ͢Έ·ͤΜͰͨ͠ɻ
ࣗݾհ • ओ ཧ - Osamu TONOMORI • @osamingo •
גࣜձࣾικ • 2016/08 ~ • Software engineer • Go ྺ • 2014/10 ~ • GAE/Go ɺ2016/08 ~ 8
ࣗݾհ
None
None
Agenda 1. ࣗݾհ 2. GAE ʹ͍ͭͯ 3. GAE ্Ͱͷ Go
app ͷצͲ͜Ζ 4. ӡ༻͢Δͱ͖ͷ Tips 5. ·ͱΊ 12
GAE ʹ͍ͭͯ
GAE ͱ • Google App Engine • Google ͕͍ͬͯΔ PaaS
ɻ • 2008 ͙Β͍͔Β͋ΔɻʢGCPͰ࠷ݹࢀʣ • Scaling Λௐ͢ΕɺແྉͰ͑Δɻ 14
GAE ͱ • Google App Engine • Google ͕͍ͬͯΔ PaaS
ɻ • 2008 ͙Β͍͔Β͋ΔɻʢGCPͰ࠷ݹࢀʣ • Scaling Λௐ͢ΕɺແྉͰ͑Δɻ • Heroku ͱಉ͡ײ͡Ͱ৮Δͱ (ʋ´ω`) ͳײ͡ʹͳΔɻ • ಠࣗͷϧʔϧɺ֮͑Δ͜ͱ͕ଟ͍ɻ 15
Standard and Flexible Environment • Standard Environment (SE) • GAE
ͱ͍ͬͯࢦ͢ͷɺ͍͍ͩͨͬͪ͜ɻ • ݴޠ੍ɺಠࣗͷϧʔϧଟ͍͕͓खܰʹࢼͤΔɻ • Go, Python, Java, PHP • Flexible Environment (FE) • Cloud Next 2017 Ͱɺ GA ʹͳͬͨɻ • Docker ͳͷͰɺಛʹ੍ແ͍ɻ 16
Flexible Environment Λ͏໘ • ωοτϫʔΫىҼͷཁٻ͕͋Δ߹ • ݻఆ IP Ͱ֎෦ଓ͠ͳ͍ͱ͍͚ͳ͍ɻ •
෦ެ։ݶఆͷαʔϏεͷΞΫηεɻ • Ұ࣌తͳσΟεΫॻ͖ࠐΈ͕ඞཁͳ߹ • ϑΝΠϧΛ࡞͍ͨ͠߹ͳͲɻ (tmpfs) 17
GAE/Go (SE) Ͱͷز͔ͭͷ੍ • Go 1.6.4 • syscall, unsafe package
ɺجຊతʹ͑ͳ͍ɻ • // +build !appengine ͷೝͷ͞… 18
GAE/Go (SE) Ͱͷز͔ͭͷ੍ • Go 1.6.4 • syscall, unsafe package
ɺجຊతʹ͑ͳ͍ɻ • // +build !appengine ͷೝͷ͞… • context.Context Λ࣋ͪӡΜͰߦ͘ɻ • context Λͬͯ DB ΞΫηεΛߦ͏ɻ • ٯʹ͍͏ͱɺcontext ͕ແ͍ͱ΄΅Կग़དྷͳ͍ɻ 19
GAE/Go (SE) Ͱͷز͔ͭͷ੍ • Go 1.6.4 • syscall, unsafe package
ɺجຊతʹ͑ͳ͍ɻ • // +build !appengine ͷೝͷ͞… • context.Context Λ࣋ͪӡΜͰߦ͘ɻ • context Λͬͯ DB ΞΫηεΛߦ͏ɻ • ٯʹ͍͏ͱɺcontext ͕ແ͍ͱ΄΅Կग़དྷͳ͍ɻ 20
Go 1.8 ͕͘Δ͔
None
None
ͭͷ
Agenda 1. ࣗݾհ 2. GAE ʹ͍ͭͯ 3. GAE ্Ͱͷ Go
app ͷצͲ͜Ζ 4. ӡ༻͢Δͱ͖ͷ Tips 5. ·ͱΊ 25
GAE ্Ͱͷ Go app ͷצͲ͜Ζ
DB ͬͯԿ͏ͷʁ
DB ͷબʹ͍ͭͯ • Cloud Datastore • NoSQL (Based BigTable) •
GAE ͷ߹ɺجຊతʹ Datastore Λར༻͢Δɻ • มଶྗઃܭྗ͕ࢼ͞ΕΔɻ 28
DB ͷબʹ͍ͭͯ • Cloud Datastore • NoSQL (Based BigTable) •
GAE ͷ߹ɺجຊతʹ Datastore Λར༻͢Δɻ • มଶྗઃܭྗ͕ࢼ͞ΕΔɻ • Cloud SQL • Managed MySQL/PostgreSQL(β) • ౦ژϦʔδϣϯͷ Latency ͕ΫιղܾࡁΈɻ 29
Cloud Datastore ͷ߹ • ެࣜͷ datastore ύοέʔδΛͰΘͳ͍ɻ • ඞͣ wrap
ͯͬͨ͠ํ͕Α͍ɻ • interface, validation ͳͲͪΌΜͱΓ·͠ΐ͏ɻ • goon ͱ͔͋ΔͷͰɺࢀߟʹ͢ΔͱΑ͍ɻ 30
Cloud Datastore ͷ߹ • ެࣜͷ datastore ύοέʔδΛͰΘͳ͍ɻ • ඞͣ wrap
ͯͬͨ͠ํ͕Α͍ɻ • interface, validation ͳͲͪΌΜͱΓ·͠ΐ͏ɻ • goon ͱ͔͋ΔͷͰɺࢀߟʹ͢ΔͱΑ͍ɻ • ͨͩɺઃܭ͕㙽ʹ͍֯͠ɻ 31
None
None
Cloud SQL ͷ߹ • ͳΜ͔Μී௨ʹ͑·͢ɻ • sql ύοέʔδͰଓཧ͢ΔͷͰɺྑ͠ͳʹɻ 34
Cloud SQL ͷ߹ • ͳΜ͔Μී௨ʹ͑·͢ɻ • sql ύοέʔδͰଓཧ͢ΔͷͰɺྑ͠ͳʹɻ • ͱ͍͑ɺ͏લʹҙ͕͋Δ…
35
None
None
ಉ࣌ଓ͕࠷େ 12 ݸ
ಉ࣌ଓ͕࠷େ 12 ݸ (Master, Slave ͷ߹ܭ)
sql.DB_SetMaxOpenConns(n int)
Vendoring ͬͯͲ͏ͳͷʁ
Vendoring ʹ͍ͭͯ • GOPATH ͕ɺϓϩδΣΫτϕʔεʹͳΔɻ 42
Vendoring ʹ͍ͭͯ • GOPATH ͕ɺϓϩδΣΫτϕʔεʹͳΔɻ • vendor σΟϨΫτϦͱ͔ɺ͑ͳ͍ɻ • dep,
glide, gvt ͳͲݢฒΈ͑·ͤΜɻ 43
Vendoring ʹ͍ͭͯ • GOPATH ͕ɺϓϩδΣΫτϕʔεʹͳΔɻ • vendor σΟϨΫτϦͱ͔ɺ͑ͳ͍ɻ • dep,
glide, gvt ͳͲݢฒΈ͑·ͤΜɻ • ےྗͰΧόʔʂʂ 44
Vendoring ʹ͍ͭͯ • GOPATH ͕ɺϓϩδΣΫτϕʔεʹͳΔɻ • vendor σΟϨΫτϦͱ͔ɺ͑ͳ͍ɻ • dep,
glide, gvt ͳͲݢฒΈ͑·ͤΜɻ • ےྗͰΧόʔʂʂ • ϓϩδΣΫτϕʔεͷґଘཧ 45
None
gb ʹΑΔvendoring • gb vendor ίϚϯυʹΑΔґଘཧ • fetch, update, purge
ͻͱ௨ΓͰ͖Δɻ 47
gb ʹΑΔvendoring • gb vendor ίϚϯυʹΑΔґଘཧ • fetch, update, purge
ͻͱ௨ΓͰ͖Δɻ • ͨͩɺinit ͚ͩαϒίϚϯυ͕ແ͍ͷͰɺےྗ 48
gb ʹΑΔvendoring • gb vonder ίϚϯυʹΑΔґଘཧ • fetch, update, purge
ͻͱ௨ΓͰ͖Δɻ • ͨͩɺinit ͚ͩαϒίϚϯυ͕ແ͍ͷͰɺےྗ 49 HPMJTUGb\\SBOHF*NQPSUT^^\\^^\\FOE^^\\SBOHF5FTU*NQPSUT^^\\^^ \\FOE^^ 71"5) cUSaOcTPSUcVOJRcHSFQ& a DPNcPSHc JO cYBSHTO*\^TIDHCWFOEPSGFUDI\^
gb ʹΑΔ GOPATH ཧ • gb gae ίϚϯυʹΑΔ GOPATH ͷཧ
• test, serve, deploy ͷ GOPATH Λղܾͯ͘͠ΕΔɻ • ެࣜఏڙͰແ͍ͷͰɺผ్Πϯετʔϧ͢Δɻ • go get -u github.com/PalmStoneGames/gb-gae 50
ConfigurationͬͯͲ͏ͳͷʁ
Configuration ʹ͍ͭͯ • The Twelve-Factor App - https://12factor.net/ • The
twelve-factor app stores config in environment variables. 52
Configuration ʹ͍ͭͯ • The Twelve-Factor App - https://12factor.net/ • The
twelve-factor app stores config in environment variables. • GAE ಉ͡ࢥͳͷͰɺڥมʹೖΕ·͠ΐ͏ɻ 53
Configuration ʹ͍ͭͯ • Test ͷͱ͖ɺͲ͏͢Δͷ͔ʁ 54
Configuration ʹ͍ͭͯ • Test ͷͱ͖ɺͲ͏͢Δͷ͔ʁ • ં֯ Go ͬͯΔΜͩ͠ɺ direnv
͓͏ɻ • ./test/.envrc ʹςετ༻ͷڥมΛઃஔ͢Δɻ 55 EJSFOWFYFDUFTUHCHBFUFTUTSDʜ
Agenda 1. ࣗݾհ 2. GAE ʹ͍ͭͯ 3. GAE ্Ͱͷ Go
app ͷצͲ͜Ζ 4. ӡ༻͢Δͱ͖ͷ Tips 5. ·ͱΊ 56
ӡ༻͢Δͱ͖ͷ Tips
Deploy ͬͯͲ͏ͳͷʁ • Traffic migration Λ͏ͱɺ͍Ζ͍ΖͰ͖Δɻ • Blue/Green deployment, Canary
Release 58
Deploy ͬͯͲ͏ͳͷʁ • Traffic migration Λ͏ͱɺ͍Ζ͍ΖͰ͖Δɻ • Blue/Green deployment, Canary
Release • context Λͬͨࣄલॲཧ 59
Deploy ͬͯͲ͏ͳͷʁ • Traffic migration Λ͏ͱɺ͍Ζ͍ΖͰ͖Δɻ • Blue/Green deployment, Canary
Release • context Λͬͨࣄલॲཧ 60
Monitoring ͬͯͲ͏ͳͷʁ • Stackdriver ͕ɺͻͱ௨Γʹͳͬͯ͘ΕΔɻ • http status code, datastore,
taskqueue etc.
Monitoring ͬͯͲ͏ͳͷʁ • Stackdriver ͕ɺͻͱ௨Γʹͳͬͯ͘ΕΔɻ • http status code, datastore,
taskqueue etc. • Error log ࢹɺStackdriver Logging ͱ࿈ܞͰ͖Δɻ • Slack ࿈ܞϥΫϥΫ
Agenda 1. ࣗݾհ 2. GAE ʹ͍ͭͯ 3. GAE ্Ͱͷ Go
app ͷצͲ͜Ζ 4. ӡ༻͢Δͱ͖ͷ Tips 5. ·ͱΊ 63
·ͱΊ • …ʹೖΔલʹ Release Notes ͷ֬ೝ IUUQTDMPVEHPPHMFDPNBQQFOHJOFEPDTTUBOEBSEHPSFMFBTFOPUFT
·ͱΊ • Go 1.8 ͍͘͜ʂʂʂ
Thanks for your attention.