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
300
スタートアップで1人目QAエンジニアになった話 / Startup first QA
nametake
3
1.3k
テスト技法の話 / Testing techniques
nametake
5
4.6k
Other Decks in Programming
See All in Programming
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
200
Jakarta EE meets AI
ivargrimstad
0
620
flutterkaigi_2024.pdf
kyoheig3
0
150
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
120
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.3k
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
受け取る人から提供する人になるということ
little_rubyist
0
250
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
CSC509 Lecture 09
javiergs
PRO
0
140
Featured
See All Featured
Designing for Performance
lara
604
68k
Rails Girls Zürich Keynote
gr2m
94
13k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Into the Great Unknown - MozCon
thekraken
32
1.5k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
A Philosophy of Restraint
colly
203
16k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Raft: Consensus for Rubyists
vanstee
136
6.6k
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ϥΠϑΛ!!!