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
Rubyの会社でRustを書くということ
Search
KOBA789
February 10, 2018
Technology
3
3.1k
Rubyの会社でRustを書くということ
Cookpad TechConf 2018 (
https://techconf.cookpad.com/2018/
) で発表した資料です。
KOBA789
February 10, 2018
Tweet
Share
More Decks by KOBA789
See All by KOBA789
令和最新版手のひらコンピュータ
koba789
14
8k
時の流れが許せない
koba789
0
120
ついに生産が終わったけどZ80でまだまだ遊びたい
koba789
5
4.4k
ISUCONの練習を楽しくたくさんやる方法
koba789
2
1.3k
Z80をRustで動かすまで年が越せない
koba789
0
250
ISUCON練習環境を最も簡単に用意する方法
koba789
2
3.3k
音をアレする
koba789
0
950
メガネとBluetooth Low Energyでお喋りする
koba789
0
1.6k
Rustでon-diskなB+Treeを作ったときの細かな話
koba789
11
1.9k
Other Decks in Technology
See All in Technology
Go で言うところのアレは TypeScript で言うとコレ / Kyoto.なんか #7
susisu
5
1.2k
AIとTDDによるNext.js「隙間ツール」開発の実践
makotot
5
650
R-SCoRe: Revisiting Scene Coordinate Regression for Robust Large-Scale Visual Localization
takmin
0
430
どこで動かすか、誰が動かすか 〜 kintoneのインフラ基盤刷新と運用体制のシフト 〜
ueokande
0
180
実践アプリケーション設計 ③ドメイン駆動設計
recruitengineers
PRO
1
150
VPC Latticeのサービスエンドポイント機能を使用した複数VPCアクセス
duelist2020jp
0
180
Android Studio の 新しいAI機能を試してみよう / Try out the new AI features in Android Studio
yanzm
0
260
mruby(PicoRuby)で ファミコン音楽を奏でる
kishima
1
210
OpenAPIから画面生成に挑戦した話
koinunopochi
0
150
Amazon Bedrock AgentCore でプロモーション用動画生成エージェントを開発する
nasuvitz
6
410
.NET開発者のためのAzureの概要
tomokusaba
0
230
開発と脆弱性と脆弱性診断についての話
su3158
1
1.1k
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
95
14k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
The Cost Of JavaScript in 2023
addyosmani
53
8.8k
Done Done
chrislema
185
16k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
[RailsConf 2023] Rails as a piece of cake
palkan
56
5.8k
Become a Pro
speakerdeck
PRO
29
5.5k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Making Projects Easy
brettharned
117
6.3k
Unsuck your backbone
ammeep
671
58k
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/