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
54k
Other Decks in Programming
See All in Programming
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
260
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
210
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
140
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
1
290
gopls を改造したら開発生産性が高まった
satorunooshie
8
240
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
23k
hotwire_or_react
harunatsujita
8
4.1k
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
200
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
250
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
270
Golang と Erlang
taiyow
8
1.9k
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
140
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
370
Designing Experiences People Love
moore
138
23k
YesSQL, Process and Tooling at Scale
rocio
167
14k
Done Done
chrislema
181
16k
How GitHub (no longer) Works
holman
311
140k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Learning to Love Humans: Emotional Interface Design
aarron
272
40k
Documentation Writing (for coders)
carmenintech
65
4.4k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
328
21k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2.1k
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.