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
2相コミットなどの実例に見るゴルーチンとチャネルの使いどころ
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
kojiaomatsu
November 13, 2021
Technology
390
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
170
Other Decks in Technology
See All in Technology
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8.5k
LLM/Agent評価:トップ営業の発言を「正解」にする 〜暗黙的正解による評価を営業資産に変える〜
takkuhiro
1
240
10年目を迎えた「ABEMA」がどのように AI 活用を推進して、AI 駆動開発にシフトしているのか / How ABEMA, entering its 10th year, is promoting the use of AI and shifting toward AI-driven development
miyukki
0
360
『モデル + ハーネス』で読み解く AIエージェント入門
oracle4engineer
PRO
2
150
ダッシュボード"開発"について 〜使われるダッシュボードのつくりかた〜
kimichan
0
150
ここは地獄!つらい朝会を体験することで、チームとしてのより良い振る舞いに気づくワークショップ / The stand-up meeting from hell in the game industry
scrummasudar
0
210
AIが実装を自走する時代の認知負債との戦い
lycorptech_jp
PRO
2
1k
凡エンジニアがこの先生きのこるためには。〜TypeScript完全に理解したい〜
alchemy1115
2
400
第67回コンピュータビジョン勉強会CVPR2026読会前編
tsukamotokenji
0
160
Aurora MySQL 8.4リリース! Rubyistが備えること / what-rubyist-should-prepare-for-aurora-mysql-8-4
fkmy
0
130
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
15
110k
Multicaで30個のミニプロジェクトをAIエージェント運用して見えてきたこと
eiei114
1
600
Featured
See All Featured
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
240
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
Discover your Explorer Soul
emna__ayadi
2
1.2k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
220
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
WENDY [Excerpt]
tessaabrams
11
38k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
The SEO identity crisis: Don't let AI make you average
varn
0
520
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