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
距離関数を極める! / SESSIONS 2024
gam0022
0
280
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
190
イベント駆動で成長して委員会
happymana
1
320
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
310
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
600
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
32
1.5k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
The Invisible Side of Design
smashingmag
298
50k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Rails Girls Zürich Keynote
gr2m
94
13k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
A Tale of Four Properties
chriscoyier
156
23k
Raft: Consensus for Rubyists
vanstee
136
6.6k
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.