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
Ractorが出たからRubyの並列処理をおさらいする
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
mokichi
February 24, 2021
Programming
880
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ractorが出たからRubyの並列処理をおさらいする
mokichi
February 24, 2021
More Decks by mokichi
See All by mokichi
Elixir以外の言語もよく使うエンジニアが考える、Phoenix LiveViewの使いどころ
mokichi
2
670
Rubyistから見たElixir
mokichi
1
550
Phoenix LiveViewをプロダクション利用してみた所感
mokichi
3
1k
Phoenix1.6で標準搭載されたLiveViewに入門してみよう
mokichi
0
300
WebエンジニアのためのKubernetesサクッと入門
mokichi
1
230
未来予知できない凡人の生存戦略
mokichi
0
130
Other Decks in Programming
See All in Programming
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
1.2k
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
190
AmebaブログはKMPから卒業します
kmars0605
0
310
Python Lambdaにおけるテストしやすい設計とAI支援の活用 / Designing Testable Python Lambda Functions with AI
kitano_yuichi
1
260
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
390
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
300
Groovy as a human and AI friendly programming language
paulk
0
140
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
1.9k
Next.js: The final boss of Web Performance
guaca
0
370
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
3
630
パスワード再設定メールのURLについて知っておこう
uyuki234
0
200
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
200
Featured
See All Featured
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
720
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
540
Believing is Seeing
oripsolob
1
260
Done Done
chrislema
187
17k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
290
Amusing Abliteration
ianozsvald
1
370
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
430
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
960
Transcript
Ractorが出たから Rubyの並列処理をおさらいする 2021/02/24 @第28回ゆるはち.it 株式会社スマートアルゴリズム 齋藤 和也
自己紹介 名前:齋藤 和也 HN:mokichi 年齢:33歳 居住:東京都 出身:福岡県 🍜 Twitter:@mokichi_s12m 株式会社スマートアルゴリズム 代表取締役 株式会社Vook
外部CTO クラウドインフラを含むサーバサイド開発やDevOps が得意 ここ数年は Elixir/Phoenix にお熱 🔥 (ビルディット社との付き合いは結構長い )
Ruby3.0で Ractor が追加されました 🎉 まだ experimental
Ractorとは • アクターモデル風の並行・並列制御機構 • 並列実行単位をRactorと呼んでいる Ractor.new{ expr } • メッセージの送受信でRactor間のコミュニケーション
• 各Ractorに少なくとも1つのスレッドがある • コントリビューター曰く「らくたー」と読むのが正しそうです (当初あーるあくたーと読んでいたのは内緒) https://www.youtube.com/watch?v=40t8EPpnujg
プロセスやスレッドじゃダメなの? 🤔
プロセスの問題点 • OSへの負荷がスレッドと比較して高い • メモリをたくさん使う (COWがあったとしても) • プロセス間でメモリ上のオブジェクトを直接共有する ことができず、別の手段でやりとりする必要がある
スレッドの問題点 • スレッド間でメモリを共有するため、複数スレッドから同じオブ ジェクトを同時に操作するとまずいことに (Mutex等使えば解消できるが、かなり気を使う) • 処理どうしに依存関係があると複雑さが増す • CRubyにはGIL(GVL)があるためスレッド安全ではあるが、マ ルチコアを活用できない
GILについて • Global Interpreter Lock の略 RubyではGVL(Giant VM Lock)という名称 •
同時に実行されるスレッドは常に1つ • I/Oの待機時には解放される ◦ WebアプリケーションのようにI/Oが処理の大部分を占めるものは マルチスレッドによる並列化の恩恵を受けられる
人類には マルチスレッドプログラミングは 難しすぎる 🤯 C++やJavaでは結構やってましたが… (お察し)
Ractorの特徴 • 異なるRactorではGILの影響を受けない • ミュータブルな変数をRactor間で共有できない ◦ ディープコピーを渡す or 所有権を移動させる •
別Ractorからのメッセージを待つことができるため、 依存関係がある処理やワーカープールを記述しやすい ◦ スレッドで同じことしようとすると、ロックが複雑に絡み合う
時間があればサンプルを少し見る
将来Ractorはこう使われる?(勝手な想像です) • Unicorn/Puma や Resque/Sidekiq の発展型 ◦ GILの影響を受けないことによる恩恵を受けられる • 機械学習
(データ収集 > 前処理 > 学習 > 予測 の全工程) ◦ Ruby自体も処理速度が向上しているし、ライブラリも結構あるみたい ◦ RubyでWebアプリ作ってるのに、そこだけわざわざPython使うのは… • 分散コンピューティング ◦ PubSubとうまく使えば別マシンのプロセスと連動できたり?
We ❤ Ruby!