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
Transcript
29 slides
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
More Decks by kojiaomatsu
See All by kojiaomatsu
FunctionBuildersから見るSwiftUIの文法
kojiaomatsu
0
180
Other Decks in Technology
See All in Technology
契約書SaaSにAIエージェントを組み込む
sansantech
PRO
0
180
プロダクションコードにおける encoding/json から encoding/json/v2 へのスムーズな移行
sansantech
PRO
1
450
Del vibe coding a un Desarrollo (agéntico) fiable
jcabot
0
160
AIで実装が加速したのに、 なぜ私は仕事の大半で人と話し続けていたのか?
say_no_w
0
190
3文字略語に騙されない! 世界一わかりやすい『EDR』超入門
kamadamakoto
1
270
Agent Harnessはどう作る?事例から学ぶAI Agentの設計思想
sergicalsix
0
340
AWS Client VPNの設定でハマったポイントとその過程での気づき
amarelo_n24
1
390
高品質と高スピードを支える品質のシフトレフトのアプローチ
goyoki
4
1.6k
小さなエージェントから始めてみよう!実践コンテキストエンジニアリング
iwamot
PRO
0
130
gradle-best-practices 使ってみた
mikanichinose
0
150
人間+AIを「チーム」としてプロセスを再設計する
littlehands
4
3.4k
思考過程から秘密が漏れる:Amazon Bedrock上のKimi K3を5つの方法で攻めたら、25回中22回漏洩した話
yama3133
1
170
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
The Curse of the Amulet
leimatthew05
4
17k
What does AI have to do with Human Rights?
axbom
PRO
1
2.5k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
121
130k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
560
Building Better People: How to give real-time feedback that sticks.
wjessup
371
20k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
460
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
770
The untapped power of vector embeddings
frankvandijk
2
2k