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.7k
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
53k
Other Decks in Programming
See All in Programming
Re:PandasAI:生成AIがデータ分析業務にもたらすパラダイムシフト【増補改訂版】
negi111111
1
870
5年分のツケを一気に払った話
soogie
3
1.2k
4年間変わらなかった YOUTRUSTのアーキテクチャ
daiki1003
0
170
Remix × Cloudflare Pages × Sentry 奮闘記 / remix-pages-sentry
nkzn
1
390
C#および.NETに対する誤解をひも解く
ymd65536
0
240
ECS向けのドリフト検知機構を実装してみた
tkikuc
0
280
ファーストペンギンBot @Qiita Hackathon 2024 予選
dyson_web
0
220
Compose Multiplatform과 Ktor로 플랫폼의 경계를 넘어보자
kwakeuijin
0
250
いまあるチームにフィットさせる Serverless そして Platform Engineeringへの挑戦 / Serverless Fits the Team You Have and Platform Engineering
seike460
PRO
2
1.4k
Pythonによるイベントソーシングへの挑戦と現状に対する考察 / Challenging Event Sourcing with Python and Reflections on the Current State
nrslib
3
950
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
6
260
ポケモンで考えるコミュニケーション / Communication Lessons from Pokémon
mackey0225
4
160
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
2
220
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
7
560
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
225
22k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
29
1.7k
How GitHub (no longer) Works
holman
311
140k
Clear Off the Table
cherdarchuk
91
320k
Bash Introduction
62gerente
608
210k
BBQ
matthewcrist
84
9.2k
Code Reviewing Like a Champion
maltzj
519
39k
Web Components: a chance to create the future
zenorocha
310
42k
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.