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
goroutineとマルチスレッドデザインパターン/ goroutine and multit...
Search
nametake
December 08, 2016
Programming
1
1.2k
goroutineとマルチスレッドデザインパターン/ goroutine and multithreaded design pattern
https://connpass.com/event/28621/
Go言語LT大会! 「最近、Go言語始めました」の会での発表資料
nametake
December 08, 2016
Tweet
Share
More Decks by nametake
See All by nametake
実例マッピングで要件のレビューサイクルを回してる話 / Example Mapping Review Cycle
nametake
1
1k
アルプ T-QAオンボーディング資料(2022年9月版) / Alp T-QA onboarding 2022-09
nametake
0
1.4k
定式化と自動化に取り組みますという話 / Work on formulation and automation
nametake
0
870
QAエンジニアが実例マッピングを2ヶ月運用した話 / Example Mapping for 2 months
nametake
3
5.7k
1人目QAエンジニアよもやま話 / QA Test Talk Vol.1
nametake
4
640
アルプでのAgile Testing / Alp Agile Testing
nametake
1
2.2k
CFD-Editorというツールを作ってみた話 / Made CFD-Editor
nametake
1
290
スタートアップで1人目QAエンジニアになった話 / Startup first QA
nametake
3
1.3k
テスト技法の話 / Testing techniques
nametake
5
4.6k
Other Decks in Programming
See All in Programming
Better Code Design in PHP
afilina
PRO
0
120
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
290
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
580
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
530
Realtime API 入門
riofujimon
0
150
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
距離関数を極める! / SESSIONS 2024
gam0022
0
280
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
Featured
See All Featured
Being A Developer After 40
akosma
86
590k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
The Cult of Friendly URLs
andyhume
78
6k
Facilitating Awesome Meetings
lara
50
6.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
4 Signs Your Business is Dying
shpigford
180
21k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
How to Ace a Technical Interview
jacobian
276
23k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Transcript
goroutineͱ ϚϧνεϨου σβΠϯύλʔϯ ߦ লޗ
ࣗݾհ • ߦ লޗ(φϝΩ γϣΰ) • 2016৽ଔ • Goݴޠྺ 5ϲ݄
goroutineͬͯ·͔͢?
GoݴޠΛޠΔ্Ͱ ֎ͤͳ͍ฒྻԽͷػೳ
͜ͷ͍ํ͋ͬͯΔʁ ͢ΕͬͲ͜Θ͍
goroutineͷߟ͑ํͱ σβΠϯύλʔϯ
GoͰͷฒߦॲཧ
υΩϡϝϯτΛॲ͢Δࣄ υΩϡϝϯτͷࢁ ম٫ Gopher͘Μͱ Χʔτ ͨ͘͞Μ͋ΔυΩϡϝϯτΛ೩͍ͨ͠
୯७ͳΞϓϩʔν Gopher͘ΜΛ2ඖ(ਓ?)ʹ
ಉظ͕ͪൃੜͯ͠͠·͏ ম٫Λ͑Δͷ1ʹ1ඖ(ਓ?)
ಉظ͕ͪൃੜͯ͠͠·͏ ম٫Λ͑Δͷ1ʹ1ඖ(ਓ?)
૿ͯ͠ޮՌ্͕͕ΓͮΒ͍
GoݴޠͰͷΞϓϩʔν
ฒྻͳॲཧ Gopher͘ΜΛฒྻʹಈ͔͢ͷͰͳ͘
ฒߦͳॲཧ Gopher͘ΜΛฒߦʹಈ͔͢
ฒߦͳॲཧ υΩϡϝϯτΛΧʔτʹੵΉGopher͘Μ
ฒߦͳॲཧ ΧʔτΛӡͿGopher͘Μ
ฒߦͳॲཧ υΩϡϝϯτΛΧʔτ͔Β͓Ζͯ͠ ೩͢Gopher͘Μ
ฒߦͳॲཧ υΩϡϝϯτΛੵΜͰ͍ͨ ΧʔτΛ͢Gopher͘Μ
Կ͕خ͍͠ͷ͔
ॲཧΛͨͳͯ͘ྑ͍
ॲཧΛͨͳͯ͘ྑ͍ ӡͿͷ͕ࣄ
ॲཧΛͨͳͯ͘ྑ͍ ೩͠ऴΘΔͷΛ ͨͳ͍
Δ͜ͱ͕ͳ͚Εࢭ·Δ͚ͩ
͜ΕΒΛ࣮ݱ͢Δػೳ • channel • Gopher͘ΜͷؒΛܨ͍Ͱ͘ΕΔ • ෳͷGopher͘Μ͕channelΛୣ͍߹͏ͷΛ͙ • select •
ෳͷGopher͘Μ͔ΒຊΛड͚औΕΔ • mutexͷύοέʔδͱ͔
ϚϧνεϨου σβΠϯύλʔϯ
ϚϧνεϨου σβΠϯύλʔϯ • Single Thread Execution • Immutable • Guarded
Suspension • Balking • Producer-Consumer • Read-Write Lock • Thread-Per-Message • Worker Thread • Future • Two-Phase Termination • Thread-Specific Storage • Active Object
channelͰղܾ • Single Thread Execution • Immutable • Guarded Suspension
• Balking • Producer-Consumer • Read-Write Lock • Thread-Per-Message • Worker Thread • Future • Two-Phase Termination • Thread-Specific Storage • Active Object
selectͰղܾ • Single Thread Execution • Immutable • Guarded Suspension
• Balking • Producer-Consumer • Read-Write Lock • Thread-Per-Message • Worker Thread • Future • Two-Phase Termination • Thread-Specific Storage • Active Object
ύοέʔδͰղܾ • Single Thread Execution • Immutable • Guarded Suspension
• Balking • Producer-Consumer • Read-Write Lock • Thread-Per-Message • Worker Thread • Future • Two-Phase Termination • Thread-Specific Storage • Active Object
ؾΛ͚ͭͳ͍ͱ͍͚ͳ͍͜ͱ
ϚϧνεϨου σβΠϯύλʔϯ • Single Thread Execution • Immutable • Guarded
Suspension • Balking • Producer-Consumer • Read-Write Lock • Thread-Per-Message • Worker Thread • Future • Two-Phase Termination • Thread-Specific Storage • Active Object
Thread-Per Message • ϝοηʔδΛड͚औΔຖʹεϨουΛཱͯΔ
Thread-Per Message • ϝοηʔδΛड͚औΔຖʹεϨουΛཱͯΔ υΩϡϝϯτΛड͚औͬͨΒ……
Thread-Per Message • ϝοηʔδΛड͚औΔຖʹεϨουΛཱͯΔ ͦΕຖʹGopher͘ΜΛ࡞Δ
Thread-Per Message • ϝοηʔδΛड͚औΔຖʹεϨουΛཱͯΔ
GoͩͱΓ͕ͪ func processHandler(w http.ResponseWriter, r *http.Request) { ~~~όϦσʔγϣϯͱ͔Payloadऔಘͱ͔~~ go Heavy()
// ͜ͷ෦ʂʂʂ w.WriteHeader(http.StatusAccepted) }
Worker Thread • ࠷ॳ͔ΒεϨουΛಈ͔͓ͯ͘͠
Worker Thread • ࠷ॳ͔ΒεϨουΛಈ͔͓ͯ͘͠ υΩϡϝϯτΛ ड͚औͬͨΒ…… !
Worker Thread • ࠷ॳ͔ΒεϨουΛಈ͔͓ͯ͘͠ ۭ͍ͯΔ ୭͔͕୲
Worker Thread • ࠷ॳ͔ΒεϨουΛಈ͔͓ͯ͘͠ ! ·ͨདྷͨΒ……
Worker Thread • ࠷ॳ͔ΒεϨουΛಈ͔͓ͯ͘͠ ۭ͍ͯΔ ୭͔͕୲
Worker Thread • ࠷ॳ͔ΒεϨουΛಈ͔͓ͯ͘͠ Gopher͘Μͷ ૿͑ͳ͍
channelͩͱ؆୯ func heavy(queue <-chan string) { url := <-queue //
ϦΫΤετॲཧ } func main() { queue := make(chan string, 32) for i := 0; i < 3; i++ { go heavy(queue) } queue <- “https://google.co.jp” queue <- “https://google.com” // লུ }
͜ΕͰ͏goroutine ා͘ͳ͍ʂʂʂ
Α͖goroutineϥΠϑΛ!!!