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
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.2k
メモリが足らない2026
koba789
4
2.7k
直接メモリアクセス
koba789
0
870
人工衛星のファームウェアをRustで書く理由
koba789
16
10k
令和最新版手のひらコンピュータ
koba789
14
9.8k
時の流れが許せない
koba789
0
7.3k
ついに生産が終わったけどZ80でまだまだ遊びたい
koba789
5
4.9k
ISUCONの練習を楽しくたくさんやる方法
koba789
3
1.6k
Z80をRustで動かすまで年が越せない
koba789
0
500
Other Decks in Technology
See All in Technology
Essential architectural thinking (revised edition)
ufried
0
100
OpenSharing について熱く語る〜AI アセットの共有について〜
kameitomohiro
0
240
使いこなすために知っておきたい Azure SRE Agent アンチパターン
torumakabe
2
410
継続的なAIコスト最適化
bgpat
1
220
LLM機能を自作して分かるSnowflake Cortex AIの強み
nayuts
0
320
More Freedom on the Same Shared GPU Cluster: A Small Team’s Experience with vCluster
nttcom
0
140
3つのアプローチで目指す チームを強くするAI駆動開発
thkt
0
130
購入ドメインでの課題と取り組み
ykagano
0
150
ハードウェアコンペでもAI駆動開発が進んでいる話
iotengineer22
0
390
Codex概要
ymiya55
0
460
組み立てて楽しむ AWS Blocks 入門
kmiya84377
0
220
Execution in the Kingdom of Agents: Reflections on Abstraction and Complexity
bcantrill
0
870
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
37
7.5k
Making Projects Easy
brettharned
120
6.8k
A Tale of Four Properties
chriscoyier
163
24k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
350
The Mindset for Success: Future Career Progression
greggifford
PRO
0
530
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Fireside Chat
paigeccino
43
4.1k
The agentic SEO stack - context over prompts
schlessera
0
970
GraphQLとの向き合い方2022年版
quramy
50
15k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
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/