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
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
From Translations to Multi Dimension Entities
alexanderschranz
2
130
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
350
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
330
Symfony Mapper Component
soyuka
2
730
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
730
CSC305 Lecture 26
javiergs
PRO
0
140
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5.1k
Producing Creativity
orderedlist
PRO
341
39k
Being A Developer After 40
akosma
87
590k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Typedesign – Prime Four
hannesfritz
40
2.4k
Making the Leap to Tech Lead
cromwellryan
133
9k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Designing for humans not robots
tammielis
250
25k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Embracing the Ebb and Flow
colly
84
4.5k
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.