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
Rubyの会社でRustを書くということ
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
KOBA789
February 10, 2018
Technology
3.3k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rubyの会社でRustを書くということ
Cookpad TechConf 2018 (
https://techconf.cookpad.com/2018/
) で発表した資料です。
KOBA789
February 10, 2018
More Decks by KOBA789
See All by KOBA789
8bit CPU 2026
koba789
7
3.1k
メモリが足らない2026
koba789
4
2.7k
直接メモリアクセス
koba789
0
850
人工衛星のファームウェアをRustで書く理由
koba789
16
10k
令和最新版手のひらコンピュータ
koba789
14
9.7k
時の流れが許せない
koba789
0
7.2k
ついに生産が終わったけどZ80でまだまだ遊びたい
koba789
5
4.9k
ISUCONの練習を楽しくたくさんやる方法
koba789
2
1.6k
Z80をRustで動かすまで年が越せない
koba789
0
480
Other Decks in Technology
See All in Technology
2026-09-11 【Snowflake World Tour Tokyo 2026】Snowflakeを起点に、AI Agentが自律稼働し続ける未来へ / Driving AI Agents with Snowflake
civitaspo
0
300
Code4Lib JAPANカンファレンス2026 開会挨拶 / Code4Lib JAPAN Conference 2026: Opening Remarks
ykiyota
0
330
なぜSRE・セキュリティは評価されないのか?守りの組織を事業成長エンジンに変えた実践
cscengineer
PRO
3
2.4k
あるけみー式LTスライド作成術
alchemy1115
1
170
AI-DLCって実際どう? 〜聞きたいこと全部聞いてみる〜
news_it_enj
0
260
GuardDuty 検知対応を DevOps Agent で効率化しようとしている話 / GuardDuty Investigations with DevOps Agent
masahirokawahara
1
350
20260912_スクラムにジェネラリストは必要か
ryugen04
0
310
2026_devsumi_ozono.pdf
o3
2
330
Amazon S3 Tablesに全部任せてみた結果——コンパクション/スナップショット管理は本当に手放せるか
shigeruoda
1
460
Omarchy Quattro の日本語設定周り
simosako
2
140
2026/09/10 Spring Bootから Jakarta EE/MicroProfileへの移行
megascus
0
300
Sigmaで作る業務アプリ
kazushiro_honma
0
110
Featured
See All Featured
So, you think you're a good person
axbom
PRO
2
2.1k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
890
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
KATA
mclloyd
PRO
35
15k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
270
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
540
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
How to Think Like a Performance Engineer
csswizardry
28
2.8k
Designing Powerful Visuals for Engaging Learning
tmiket
1
540
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
330
Transcript
KOBA789ʢখྛलʣ ΠϯϑϥετϥΫνϟʔ෦ RubyͷձࣾͰ RustΛॻ͘ͱ͍͏͜ͱ Cookpad Inc. Feb 10th, 2018
ࣗݾհ 2 ɾ2017৽ଔ ɾΠϯϑϥετϥΫνϟʔ෦ σʔλج൫άϧʔϓ KOBA789ʢখྛलʣ
RubyͷձࣾͰ RustΛॻ͘ͱ͍͏͜ͱ
4 Ruby
5 Go Java Ruby
6 Go Java Hako (DockerσϓϩΠج൫) Ruby
7 Go Java Hako (DockerσϓϩΠج൫) Ruby
8 Go Java Ruby Rust Hello !
9 Ruby͚ͩͷձࣾ Ͱͳ͍
10 Push௨৴ج൫
ɾΠϕϯτൃੜ͝ͱʹૹ৴ ɾʮͭ͘ΕΆ͕ಧ͍ͨʯ ɾ৴গͳ͍ ɾಛఆͷʹҰ੪৴ ɾٳϢʔβʔͷૌٻ ɾ৴ଟ͍ ɾඦສ௨ن ɾݟੵΓ͕େ ϓογϡ௨ 11
৴ Ұ੪৴
12 App S3 ج൫ SNS 1. ड৴ઃఆΛΫΤϦ 2. ARNΛΫΤϦ 3.
S3ʹॻ͖ࠐΈ 4. S3͔ΒಡΈग़͢ 5. SNSૹ৴ ᶃ ᶄ ᶅ ᶇ ᶆ MySQL
13 ड৴ઃఆΛΫΤϦ ARNΛΫΤϦ SNSૹ৴ S3ʹॻ͖ࠐΉ S3͔ΒಡΈग़͢
14 ड৴ઃఆΛΫΤϦ ARNΛΫΤϦ SNSʹૹ৴
15 ड৴ઃఆΛΫΤϦ ARNΛΫΤϦ SNSʹૹ৴ { چج൫ { App
16 World's Largest Rails Monolith
S3 ج൫ SNS 17 App New! MySQL
S3 ج൫ SNS New! DBڞ༗ 18 ίϐϖϩδοΫ App MySQL
19 ཧͷPush௨৴ج൫
20 ड৴ઃఆΛΫΤϦ ARNΛΫΤϦ SNSʹૹ৴ { } چج൫ ৽ج൫
21 ϢʔβʔIDࢦఆ ARNࢦఆ λʔήοτ
22 ड৴ઃఆͰϑΟϧλ
23 S3 ج൫ SNS MySQL େྔ৴ ৴ HTTP API
24 S3 ج൫ SNS MySQL େྔ৴ ৴ HTTP API ϢʔβʔIDͱϝοηʔδ͑͞
์ΓࠐΊ৴Ͱ͖Δ
ɾΠϕϯτൃੜ͝ͱʹૹ৴ ɾʮͭ͘ΕΆ͕ಧ͍ͨʯ ɾ৴গͳ͍ ɾಛఆͷʹҰ੪৴ ɾٳϢʔβʔͷૌٻ ɾ৴ଟ͍ ɾඦສ௨ن ɾݟੵΓ͕େ ϓογϡ௨ 25
৴ Ұ੪৴
ɾΠϕϯτൃੜ͝ͱʹૹ৴ ɾʮͭ͘ΕΆ͕ಧ͍ͨʯ ɾ৴গͳ͍ ɾಛఆͷʹҰ੪ૹ৴ ɾٳϢʔβʔͷૌٻ ɾ৴ଟ͍ ɾඦສ௨ن ɾݟੵΓ͕େ ϓογϡ௨ 26
৴ ΞϓϦϚʔέςΟϯά
ɾΠϕϯτൃੜ͝ͱʹૹ৴ ɾʮͭ͘ΕΆ͕ಧ͍ͨʯ ɾ৴গͳ͍ ɾಛఆͷʹҰ੪ૹ৴ ɾٳϢʔβʔͷૌٻ ɾ৴ଟ͍ ɾඦສ௨ن ɾݟੵΓ͕େ ϓογϡ௨ 27
৴ ΞϓϦϚʔέςΟϯά ߴͳdry-run ඦສ௨ΛͰ
28 RubyͰ࡞Δͷେม
Ruby or else 29 ɾɾ҆શੑɾฒߦੑʹϑΥʔΧε ɾίϯύΠϥ͕σʔλڝ߹Λݕࠪ ɾτϨΠτʹΑΔδΣωϦΫε Rust
30 Rust is not magic
31 ड৴ઃఆΛΫΤϦ ARNΛΫΤϦ SNSʹૹ৴
32 ड৴ઃఆΛΫΤϦ ARNΛΫΤϦ SNSʹૹ৴ 6ms 6ms }✕ 100ສ = 3࣌ؒ
33 Inspired by facebook/dataloader https://github.com/facebook/dataloader
34 ΫΤϦΛ·ͱΊΔ
35 ... WHERE user_id = 1; ... WHERE user_id =
2; ... WHERE user_id = 3; ... WHERE user_id IN (1, 2, 3);
ΫΤϦΛ·ͱΊΔ 36 WHERE user_id = ? →6ms (only 1 id)
WHERE user_id IN (?, ?, ... ?) →11ms (1000 ids) ϕϯνϚʔΫͷ݁Ռɺઍ͘Β͍͕Α͍ ࠷దͳόοναΠζ
ΫΤϦΛ·ͱΊΔ 37 ɾΩϡʔʹuser_idΛೖΕΔ ɾΩϡʔʹཷ·͍ͬͯΔuser_idΛҰؾʹऔΓग़͢ ɾIN (...) ͷதʹల։ͯ͠DBΫΤϦ ΞϧΰϦζϜ
38 KOBA789/batch-recv-rs https://github.com/KOBA789/batch-recv-rs
KOBA789/batch-recv-rs 39 MFU UY SY DSPTTCFBN@DIBOOFMVOCPVOE MFUDIVOL7FD@SY CBUDI@SFDW
VOXSBQ DPMMFDU ͍ํ
εϨουؒͷϝοηʔδύογϯάʹ͑Δ Multi-producer multi-consumerͳFIFOΩϡʔ SenderͱReceiver͔ΒͳΔ MFU UY SY DSPTTCFBN@DIBOOFMVOCPVOE KOBA789/batch-recv-rs
40 crossbeam_channel
KOBA789/batch-recv-rs 41 fn recv(&self) -> Result<T, RecvError> Ωϡʔͷத͔Β࠷ॳͷཁૉΛऔΓग़͢ϝιου ཁૉ͕ͳ͚ΕεϨουΛϒϩοΫ͢Δʢॏཁʣ crossbeam_channel::Receiver
KOBA789/batch-recv-rs 42 fn try_iter(&self) -> TryIter<T> ΩϡʔͷதΛΠςϨʔλͱͯ͠ಘΔϝιου impl<'a, T> Iterator
for TryIter<'a, T> ͪΖΜIteratorτϨΠτΛ࣮͍ͯ͠Δ crossbeam_channel::Receiver
KOBA789/batch-recv-rs 43 fn take(self, n: usize) -> Take<Self> ΠςϨʔλ͔Βઌ಄nݸͷཁૉ͚ͩͷΠςϨʔλΛ࡞Δϝιου std::iter::Iterator
KOBA789/batch-recv-rs 44 MFUGJSTUTFMGSFDW MFUSFTUTFMGUSZ@JUFS UBLF O MFUJUFSWFD<GJSTU> JOUP@JUFS
DIBJO SFTU 0L JUFS Έ߹ΘͤΔ
45 Ωϡʔ ϝΠϯ εϨου ΫΤϦ εϨου
batch_recv(3) 46 1 Ωϡʔ ϝΠϯ εϨου ΫΤϦ εϨου
47 1 working... Ωϡʔ ϝΠϯ εϨου ΫΤϦ εϨου
48 1 working... 2 Ωϡʔ ϝΠϯ εϨου ΫΤϦ εϨου
49 1 working... 2 Ωϡʔ ϝΠϯ εϨου ΫΤϦ εϨου
50 1 working... 2 5 4 3 Ωϡʔ ϝΠϯ εϨου
ΫΤϦ εϨου
51 1 working... 2 4 3 5 Ωϡʔ ϝΠϯ εϨου
ΫΤϦ εϨου
52 2 4 3 5 Ωϡʔ ϝΠϯ εϨου ΫΤϦ εϨου
batch_recv(3) 53 2 4 3 5 Ωϡʔ ϝΠϯ εϨου ΫΤϦ
εϨου
54 2 4 3 5 Ωϡʔ ϝΠϯ εϨου ΫΤϦ εϨου
55 2 4 3 5 working... } batched Ωϡʔ ϝΠϯ
εϨου
56 Q. ΫΤϦ݁Ռ Ͳ͏ͬͯฦ͢?
ΫΤϦ݁ՌͲ͏ͬͯฦ͢? 57 futures::sync::oneshot Ұ͚͔ͩ͠ૹΕͳ͍ΩϡʔͷΑ͏ͳͷ SenderɹɹͱReceiverɹɹ͔ΒͳΔ ೖ ग़ ʹΛೖΕΔͱ ͔Βग़ͯ͘Δ ೖ
ग़
58 ೖ 1 ग़ Ωϡʔ ϝΠϯ εϨου ΫΤϦ εϨου
59 ೖ 1 ग़ Ωϡʔ ϝΠϯ εϨου ΫΤϦ εϨου
60 ೖ 1 ग़ A Ωϡʔ ϝΠϯ εϨου ΫΤϦ εϨου
61 ೖ 1 ग़ A A Ωϡʔ ϝΠϯ εϨου ΫΤϦ
εϨου
62 Q.ΫΤϦ͕ ͨ͘͞Μ͋ͬͨΒ?
63 ೖ 2 ग़ ೖ 1 ೖ 3 ग़ ग़
64 ೖ 2 ग़ ೖ 1 ೖ 3 ग़ ग़
όοναΠζͷ εϨου͕ඞཁ ͜ΕͰࠔΔ
65 Tokio + futures-rs https://tokio.rs/
Tokio + futures-rs 66 ɾΠϕϯτϧʔϓͷ࣮ ɾ1ݸҎ্ͷFutureΛ࣮ߦ ɾϊϯϒϩοΩϯά I/O API ɾFutureτϨΠτ
ɾJSͷPromiseͱ ಉ༷ͷ֓೦ ɾFutureͷίϯϏωʔλ ɾɹɹɹɹ͜Εͷػೳ Tokio futures-rs ೖ ग़
Tokio + futures-rs 67 futures::sync::oneshot Ұ͚͔ͩ͠ૹΕͳ͍ΩϡʔͷΑ͏ͳͷ ɹɹΠϕϯτϧʔϓͰࢹͰ͖Δ ग़
68 ΠϕϯτϧʔϓΛ͑ 1εϨουͰͨ͘͞Μͷ "ग़"Λͪ߹ΘͤͰ͖Δ
69 ೖ 2 ग़ ೖ 1 ೖ 3 ग़ ग़
Tokio + futures-rs 70 ɾΩϡʔͷ͜͏ͷεϨου͔ΒΛฦͯ͠Β͏͜ͱ͕Ͱ͖Δ ɾϒϩοΩϯάͳॲཧΛFutureʹม͍ͯ͠ΔͱΈͳͤΔ oneshot::Senderɹ ΛΩϡʔೖΕΔύλʔϯ ೖ
71 KOBA789/batch-loader-rs https://github.com/KOBA789/batch-loader-rs
KOBA789/batch-loader-rs 72 ɾKeyͷΠςϨʔλ͔ΒValueͷྻΛฦ͢ϝιουΛ ࣮Ͱ͖ΕSQLҎ֎ʹద༻Մೳ ɾࠓճͷྫͰKey=ϢʔβʔID, Value=ςʔϒϧͷߦ Key-ValueతͳҙͷΫΤϦΛόονԽ
࠷ޙʹ 73 ɾͱʹ͔͘ϚϧνεϨου͕҆શ ɾϚϧνεϨουͱΠϕϯτۦಈͷ͍͍ͱ͜औΓ͕Ͱ͖Δ ɾ҆৺ͯ͠ߴԽʹऔΓΊΔ ɾ൚༻ϥΠϒϥϦΛ࡞Γ͍͢ܕγεςϜ Rustͷ͍͍ͱ͜Ζ
74 ͜͏ͯ͠ ϓογϡ௨৴ج൫ RustͰॻ͖͞Ε·ͨ͠
75 Ruby͚ͩ͡Όͳ͍ దͳݴޠͰ Ϋʔϧʹ՝ղܾ
76 RustΛॻ͘Πϯλʔϯγοϓ https://internship.cookpad.com/2018/spring/