Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
2相コミットなどの実例に見るゴルーチンとチャネルの使いどころ
Search
kojiaomatsu
November 13, 2021
Technology
410
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
2相コミットなどの実例に見るゴルーチンとチャネルの使いどころ
kojiaomatsu
November 13, 2021
More Decks by kojiaomatsu
See All by kojiaomatsu
FunctionBuildersから見るSwiftUIの文法
kojiaomatsu
0
180
Other Decks in Technology
See All in Technology
Claude Code on Bedrock で統制をかける小ネタ集/claude-code-bedrock-governance-tips
emiki
1
12k
Metadata - Section 2: Simple Metadata & Meta Tags
mohab1
0
140
[re:Invent2026事前勉強会(有志開催)]続きは、ラスベガスの廊下で / continue-in-the-vegas-hallway
sh_fk2
0
200
AIをリアル世界に解き放つ 〜M5Stack×AIであなたのアイディアを手の平に〜
hamadakoji
1
530
(swiftc) NonCopyableとライフタイム修飾子
teamhimeh
0
130
How we choose session proposals
kawaguti
PRO
0
170
Kiro Crewで「みのるん式」仕事術やってみた
minorun365
PRO
3
1.1k
Filter What the LLM Reads: RAG Governance with AgentCore Gateway
yakumo
0
110
野良MCPサーバーを排除せよ!MCPサーバーのガバナンス
yukiogawa
1
240
「作れる」と「リリースできる」の間にあったもの── PdMを外して見えた、PdMがやるべき仕事/Buildable ≠ Shippable: What Removing the PM Taught Me About the PM’s Job
yappli_developers
0
270
DevelopersIO 2026 Tokyo 現時点の衛星通信サービスの現状を整理してみる
maroon1st
0
300
LLM Content Moderationを支える評価・改善ループの実践
suikabar
2
350
Featured
See All Featured
Un-Boring Meetings
codingconduct
0
460
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.4k
GitHub's CSS Performance
jonrohan
1033
470k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
460
Faster Mobile Websites
deanohume
310
32k
Building the Perfect Custom Keyboard
takai
2
920
My Coaching Mixtape
mlcsv
0
360
Practical Orchestrator
shlominoach
192
12k
GraphQLとの向き合い方2022年版
quramy
50
15k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
2
410
Transcript
2 Koji Aomatsu 2021 . 11 . 1 3 .
None
None
# 2 視 視 1 : N
# iOS Go Go # GO API
None
# Cloud SQL Datastore # DB # 2
# 2 Begin, Prepare, Commit XA Transaction , 2 MySQL
PostgreSQL
# 視 DB 規 # 視
channel goroutine 1 goroutine 2 視 Datastore Cloud SQL
# 視 視 sync.WaitGroup 規 // Cloud SQL -> Datastore
// ॲཧ201͕ऴΘͬͨ͜ͱΛΒͤΔ c1 := make(chan int) // Cloud SQL -> Datastore // ॲཧ202Ͱબ͞Εͨঢ়ଶΛ͑Δ c2 := make(chan int) // Cloud SQL -> Datastore // Prepare (err != nil ͳΒࣦഊ͍ͯ͠Δ) dbPrepareCh := make(chan error) // Datastore -> Cloud SQL // DatastoreͷτϥϯβΫγϣϯ݁Ռ dbTxResultCh := make(chan error, 1)
channel goroutine 1 goroutine 2 視 Datastore Cloud SQL
// Datastore go func() { defer close(dsTxResultCh) begin() doSomething(101) <-c1
doSomething(102) state := <-c2 doSomething(state) // Prepare err := <-dbPrepareCh if err != nil { dsTxResultCh <- err rollback() } else { err = commit() dsTxResultCh <- err } }() # defer 視 dbPrepareCh
// Datastore go func() { ... doSomething(101) _, ok :=
<-c1 if !ok { rollback() return } doSomething(102) state := <-c2 err := doSomething(state) if err != nil { rollback() // ϒϩοΫΛղআ͢Δඞཁ͕ग़Δ <-dbPrepareCh return } ... }() # select
channel goroutine 1 goroutine 2 視 Datastore Cloud SQL
// Cloud SQL go func() { defer close(c1) defer close(c2)
defer close(dbPrepareCh) begin() doSomething(201) c1 <- 0 doSomething(202) c2 <- SomeState err := doSomething(203) dbPrepareCh <- err err = <-dsTxResultCh if err != nil { commit() } else { rollback() } }() # defer dbPrepareCh Prepare dsTxResultCh Datastore
# #
# 規 規
None
# API # 視 #
# API 30 GAE 10% # runtime.NumGoroutine() 10%
# // 3000ඵ͔͔Δ func handle1() { for i := 0;
i < 1000; i++ { send(i) } } // 3ඵͰऴΘΔ func handle2() { for i := 0; i < 1000; i++ { go send(i) } } func send(num int) { time.Sleep(3 * time.Second) fmt.Printf("sent %v\n", num) }
# func handle() { c := make(chan int, 300) go
func() { defer close(c) for i := 0; i < 10000; i++ { c <- i } }() var wg sync.WaitGroup for i := 0; i < 100; i++ { wg.Add(1) go func() { defer wg.Done() for { num, ok := <-c if !ok { return } send(num) } }() } wg.Wait() }
# 1
# API GAE Context log
None
# 規 視 2 3 1
# API DB
Thank you for watching. Twitter @kojiaomatsu