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
Node学園 25限 Introduction to Rust
Search
Akito0107
April 24, 2017
Technology
6
1.4k
Node学園 25限 Introduction to Rust
Node学園 25限の発表資料です。
Akito0107
April 24, 2017
Tweet
Share
More Decks by Akito0107
See All by Akito0107
テスタビリティの高いGoのAPIサーバを開発しよう
akito0107
2
8.3k
TypeScriptのコマンドラインパーサー
akito0107
1
470
Starting TDD with Node.js
akito0107
3
5.8k
Other Decks in Technology
See All in Technology
RubyのWebアプリケーションを50倍速くする方法 / How to Make a Ruby Web Application 50 Times Faster
hogelog
3
950
プロダクト活用度で見えた真実 ホリゾンタルSaaSでの顧客解像度の高め方
tadaken3
0
180
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
210
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
10
1.1k
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
1
110
DynamoDB でスロットリングが発生したとき/when_throttling_occurs_in_dynamodb_short
emiki
0
260
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
890
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
6
660
Lambdaと地方とコミュニティ
miu_crescent
2
370
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
190
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
420
Featured
See All Featured
Side Projects
sachag
452
42k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
130
Raft: Consensus for Rubyists
vanstee
136
6.6k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Teambox: Starting and Learning
jrom
133
8.8k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Six Lessons from altMBA
skipperchong
27
3.5k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Automating Front-end Workflow
addyosmani
1366
200k
Transcript
Introduction to Rust Akito Ito (@Akito0107) NodeֶԂ25࣌ݶ
ࣗݾհ • ҏ౻ ӯ (@Akito0107) • Twitter / mstdn /
Githubେମ͜ΕͰ͢ • ϦΫϧʔτςΫϊϩδʔζͱ͍͏ձࣾͰ ιϑτΣΞΤϯδχΞΛ͍ͬͯ·͢ɻ • ීஈjs()ॻ͍ͯ·͢
ͪΐͬͱհ ઌिWʹͳΓ·ͨ͠ʂ
None
Agenda • Rustͱ • RustͷԿ͕৽͍͠ͷ͔ • Rustͷ׆༻Λߟ͑Δ
Rustͱ • ొ࣌ظ2010͝Ζɻ201510݄ʹ1.0ͷ ϦϦʔε • ओ։ൃऀ: Graydon Hoare • ϚϧνύϥμΠϜݴޠ
• ҆શੑɺฒྻੑΛओ؟
Rustͷ༻్ • System Programming • Network Programming • Kernel (OS
/ Device Driver / rust.koͰggr ) • Web Assembly (LLVMͷԸܙ) • etc…
Rust࠾༻اۀ • Mozilla • Dwango • ࢄfs • Dropbox •
lossless compression
RustͷԿ͕৽͍͠ͷ͔ • ϝϞϦཧ • खಈ / Smart Ptr / GCͳͲͷطଘͷΈͱ
ҰઢΛը͢Δ • ҆શʹϝϞϦͷཧΛߦ͏ => ॴ༗ݖͱ͍͏֓೦
ϝϞϦྖҬͷछྨ • ΦϒδΣΫτΛಈతʹ֬อ͢ΔͨΊʹ༻͍Δ ϝϞϦྖҬʹStackͱHeapͷ2छྨ͋Δ
Stack • ̍ͭͷؔαϒϧʔνϯͰͷΈ༻͞Ε ΔΦϒδΣΫτͷ֬อʹ༻͍ΒΕΔ • είʔϓ͔Βൈ͚Δͱ։์͞ΕΔ • ߴʹ࣮ߦ͞ΕΔ
Heap • ෳͷαϒϧʔνϯɺؔͰ͍·Θ͞ΕΔΦϒδΣ Ϋτͷ֬อʹ༻͍ΒΕΔ • ໌ࣔతʹ։์͕ඞཁ (ण໋ͷཧ) • (Stackʹൺ) Ұൠతʹ
• σʔλߏͷheapͱ͕ؔͳ͍
StackͱHeap (Cͷྫ) 1 int foo() { 2 int len =
100; 3 int* head = (int*) malloc(sizeof(int) * len); 4 /* do some work.... */ 5 free(head); 6 return 0; 7 }
StackͱHeap (Cͷྫ) 1 int foo() { 2 int len =
100; 3 int* head = (int*) malloc(sizeof(int) * len); 4 /* do some work.... */ 5 free(head); 6 return 0; 7 } <= StackʹlenΛpush
StackͱHeap (Cͷྫ) 1 int foo() { 2 int len =
100; 3 int* head = (int*) malloc(sizeof(int) * len); 4 /* do some work.... */ 5 free(head); 6 return 0; 7 } ⊖ HeapʹྖҬΛ֬อ
StackͱHeap (Cͷྫ) 1 int foo() { 2 int len =
100; 3 int* head = (int*) malloc(sizeof(int) * len); 4 /* do some work.... */ 5 free(head); 6 return 0; 7 } <= Heap͔Β໌ࣔతʹ։์
StackͱHeap (Cͷྫ) 1 int foo() { 2 int len =
100; 3 int* head = (int*) malloc(sizeof(int) * len); 4 /* do some work.... */ 5 free(head); 6 return 0; 7 } <= Block͕ऴྃɺlen͕stack͔Βpop͞ΕΔ
ϝϞϦཧখൌ (1) • CݴޠHeapͷཧΛखಈͰ͍ͯͨ͠ɻ • malloc() / free() • ਓྨʹ·ͩૣ͔ͬͨ
खಈͰͷϝϞϦཧ 1 int foo() { 2 int len = 100;
3 int* head = (int*) malloc(sizeof(int) * len); 4 /* do some work.... */ 5 free(head); 6 return 0; 7 } ͜͜Ͱ֬อ
खಈͰͷϝϞϦཧ 1 int foo() { 2 int len = 100;
3 int* head = (int*) malloc(sizeof(int) * len); 4 /* do some work.... */ 5 free(head); 6 return 0; 7 } ͜͜Ͱ։์
CݴޠͰͷϝϞϦཧ • ಈతʹϝϞϦΛ֬อͨ͠ΒɺඞͣࣗͰղ์͠ͳ ͚ΕͳΒͳ͍ • มͷण໋ΛखಈͰཧ͢Δͷਓྨʹ͍͠ • free()Λॻ͖ΕΔ <= memory
leak • free()ͨ͠ϙΠϯλΛࢀর <= Seg fault
ϝϞϦཧখൌ(2) • Garbage Collector (GC) ͷొ • ͍Βͳ͘ͳͬͨHeapྖҬͷΦϒδΣΫτΛॲཧܥ͕ऩ ू͠ɺࣗಈͰ։์ͯ͘͠ΕΔ(ण໋ཧͷࣗಈԽ) •
Java / Ruby / Python / Go… ࠓΒΕ͍ͯΔଟ͘ͷॲཧܥGCΛ࣮ • ͪΖΜJavascript͜Ε
GCݴޠʹ͓͚ΔϝϞϦཧͷ Έ • ੜ͖ͯΔΦϒδΣΫτͱࢮΜͰΔΦϒδΣΫ τΛผ͠ɺࢮΜͰΔΦϒδΣΫτΛ։์ 7.)FBQ 3PPU 0CK " #
$ %
GCͷ • ॏ͍ • GC͕͍ͬͯΔؒॲཧ͕ࢭ·Δ (Stop The world) • ॲཧܥ͕ෳࡶʹͳΔ
• ਓྨద߹Ͱ͖͕ͨϚγϯʹͱͬͯૣ͗ͨ͢
͜͜·Ͱͷ·ͱΊ • StackྖҬͱHeapྖҬ͕͋Δ • HeapྖҬͷมͷण໋ΛͲ͏ͬͯཧ͢Δ ͔ͷ • खಈ => GC
(=> ϗϯτC++ͷεϚʔτϙΠϯλ͋Δ͚ͲׂѪ) ҆શੑͱͷτϨʔυΦϑ
RustͷΞϓϩʔν • ͱ҆શੑΛཱ྆ͤ͞Δ • GC༻͍ͳ͍ • มͷण໋ͷཧʹର͠ɺॴ༗ݖγεςϜͰ ղܾΛࢼΈͨ
RustͷϝϞϦϞσϧ • RustͷDefaultStackͷAllocate BEES OBNF WBM O ʜ
ϝϞϦStack 1 struct Foo { 2 pub n: u32, 3 } 4 5 impl Foo { 6 fn new() -> Foo { 7 Foo { n: 42 } 8 } 9 } 10 11 fn main() { 12 let foo = Foo::new(); 13 let bar = 12; 14 } ←Start
RustͷϝϞϦϞσϧ • RustͷDefaultStackͷAllocate BEES OBNF WBM O ʜ
CBS GPP 'PP\O^ ϝϞϦStack 1 struct Foo { 2 pub n: u32, 3 } 4 5 impl Foo { 6 fn new() -> Foo { 7 Foo { n: 42 } 8 } 9 } 10 11 fn main() { 12 let foo = Foo::new(); 13 let bar = 12; 14 }
RustͷϝϞϦϞσϧ • RustͷDefaultStackͷAllocate BEES OBNF WBM O ʜ
Stack 1 struct Foo { 2 pub n: u32, 3 } 4 5 impl Foo { 6 fn new() -> Foo { 7 Foo { n: 42 } 8 } 9 } 10 11 fn main() { 12 let foo = Foo::new(); 13 let bar = 12; 14 }←͜͜Ͱղ์
ϝϞϦϞσϧʢؔݺͼग़͠ʣ 1 fn bar() { 2 let a = 10;
3 let b = 15; 4 println!("{}", a + b); 5 } 6 7 fn main() { 8 let foo = Foo::new(); 9 bar(); 10 } 11 BEES OBNF WBM O ʜ Stack
ϝϞϦϞσϧʢؔݺͼग़͠ʣ 1 fn bar() { 2 let a = 10;
3 let b = 15; 4 println!("{}", a + b); 5 } 6 7 fn main() { 8 let foo = Foo::new(); 9 bar(); 10 } 11 BEES OBNF WBM O ʜ GPP 'PP\O^ Stack ←call
ϝϞϦϞσϧʢؔݺͼग़͠ʣ 1 fn bar() { 2 let a = 10;
3 let b = 15; 4 println!("{}", a + b); 5 } 6 7 fn main() { 8 let foo = Foo::new(); 9 bar(); 10 } 11 BEES OBNF WBM O ʜ C B GPP 'PP\O^ Stack ←call bar()ͷstack frame
ϝϞϦϞσϧʢؔݺͼग़͠ʣ 1 fn bar() { 2 let a = 10;
3 let b = 15; 4 println!("{}", a + b); 5 } 6 7 fn main() { 8 let foo = Foo::new(); 9 bar(); 10 } 11 BEES OBNF WBM O ʜ GPP 'PP\O^ Stack ← end
ϝϞϦϞσϧʢؔݺͼग़͠ʣ 1 fn bar() { 2 let a = 10;
3 let b = 15; 4 println!("{}", a + b); 5 } 6 7 fn main() { 8 let foo = Foo::new(); 9 bar(); 10 } 11 BEES OBNF WBM O ʜ Stack ← end
Heap Allocation • ͪΖΜHeap AllocationͰ͖Δ • std::boxed::BoxΛ͏ 1 use std::boxed::Box;
2 fn boxed_foo() -> Box<Foo> { 3 Box::new(Foo::new()) 4 } 5 fn main() { 6 let foo = boxed_foo(); 7 println!("{}", foo.n); 8 }
BoxΛͬͨͱ͖ͷϝϞϦ BEES OBNF WBM O ʜ BEES
OBNF WBM Stack heap 1 use std::boxed::Box; 2 fn boxed_foo() -> Box<Foo> { 3 Box::new(Foo::new()) 4 } 5 fn main() { 6 let foo = boxed_foo(); 7 println!("{}", foo.n); 8 }
BoxΛͬͨͱ͖ͷϝϞϦ BEES OBNF WBM O ʜ GPP
BEES OBNF WBM Stack heap 1 use std::boxed::Box; 2 fn boxed_foo() -> Box<Foo> { 3 Box::new(Foo::new()) 4 } 5 fn main() { 6 let foo = boxed_foo(); 7 println!("{}", foo.n); 8 } ←call
BoxΛͬͨͱ͖ͷϝϞϦ BEES OBNF WBM O ʜ GPP
BEES OBNF WBM Stack heap 1 use std::boxed::Box; 2 fn boxed_foo() -> Box<Foo> { 3 Box::new(Foo::new()) 4 } 5 fn main() { 6 let foo = boxed_foo(); 7 println!("{}", foo.n); 8 } ←call
BoxΛͬͨͱ͖ͷϝϞϦ BEES OBNF WBM O ʜ GPP
BEES OBNF WBM " 'PP\O^ Stack heap 1 use std::boxed::Box; 2 fn boxed_foo() -> Box<Foo> { 3 Box::new(Foo::new()) 4 } 5 fn main() { 6 let foo = boxed_foo(); 7 println!("{}", foo.n); 8 } ←call
BoxΛͬͨͱ͖ͷϝϞϦ BEES OBNF WBM O ʜ GPP
" BEES OBNF WBM " 'PP\O^ Stack heap 1 use std::boxed::Box; 2 fn boxed_foo() -> Box<Foo> { 3 Box::new(Foo::new()) 4 } 5 fn main() { 6 let foo = boxed_foo(); 7 println!("{}", foo.n); 8 } ←return
BoxΛͬͨͱ͖ͷϝϞϦ BEES OBNF WBM O ʜ GPP
" BEES OBNF WBM " 'PP\O^ Stack heap 1 use std::boxed::Box; 2 fn boxed_foo() -> Box<Foo> { 3 Box::new(Foo::new()) 4 } 5 fn main() { 6 let foo = boxed_foo(); 7 println!("{}", foo.n); 8 }←End
BoxΛͬͨͱ͖ͷϝϞϦ BEES OBNF WBM O ʜ GPP
" BEES OBNF WBM Stack heap 1 use std::boxed::Box; 2 fn boxed_foo() -> Box<Foo> { 3 Box::new(Foo::new()) 4 } 5 fn main() { 6 let foo = boxed_foo(); 7 println!("{}", foo.n); 8 }←End ࢀরઌHeapྖҬΛղ์
BoxΛͬͨͱ͖ͷϝϞϦ BEES OBNF WBM O ʜ BEES
OBNF WBM Stack heap 1 use std::boxed::Box; 2 fn boxed_foo() -> Box<Foo> { 3 Box::new(Foo::new()) 4 } 5 fn main() { 6 let foo = boxed_foo(); 7 println!("{}", foo.n); 8 }←End
͜ͷέʔεΛߟ͑ͯΈΑ͏ 1 fn print_n(foo2: Box<Foo>) { 2 println!("{}", foo2.n); 3
} 4 fn main() { 5 let foo = boxed_foo(); 6 print_n(foo); 7 println!("{}", foo.n); 8 }
͜ͷέʔεΛߟ͑ͯΈΑ͏ 1 fn print_n(foo2: Box<Foo>) { 2 println!("{}", foo2.n); 3
} 4 fn main() { 5 let foo = boxed_foo(); 6 print_n(foo); 7 println!("{}", foo.n); 8 } BEES OBNF WBM O ʜ GPP " BEES OBNF WBM " 'PP\O^ Stack heap
͜ͷέʔεΛߟ͑ͯΈΑ͏ 1 fn print_n(foo2: Box<Foo>) { 2 println!("{}", foo2.n); 3
} 4 fn main() { 5 let foo = boxed_foo(); 6 print_n(foo); 7 println!("{}", foo.n); 8 } BEES OBNF WBM O ʜ GPP " GPP " BEES OBNF WBM " 'PP\O^ Stack heap ←call
͜ͷέʔεΛߟ͑ͯΈΑ͏ 1 fn print_n(foo2: Box<Foo>) { 2 println!("{}", foo2.n); 3
} 4 fn main() { 5 let foo = boxed_foo(); 6 print_n(foo); 7 println!("{}", foo.n); 8 } BEES OBNF WBM O ʜ GPP " GPP " BEES OBNF WBM Stack heap ←End foo2ࢀরઌΛղ์
͜ͷέʔεΛߟ͑ͯΈΑ͏ 1 fn print_n(foo2: Box<Foo>) { 2 println!("{}", foo2.n); 3
} 4 fn main() { 5 let foo = boxed_foo(); 6 print_n(foo); 7 println!("{}", foo.n); 8 } BEES OBNF WBM O ʜ GPP " BEES OBNF WBM Stack heap ← ͜͜
͜ͷέʔεΛߟ͑ͯΈΑ͏ 1 fn print_n(foo2: Box<Foo>) { 2 println!("{}", foo2.n); 3
} 4 fn main() { 5 let foo = boxed_foo(); 6 print_n(foo); 7 println!("{}", foo.n); 8 } BEES OBNF WBM O ʜ GPP " BEES OBNF WBM Stack heap ← !? fooࢀরઌ͕ղ์ࡁʁ
͜ΕίϯύΠϧΤϥʔʹͳΔ 1 fn print_n(foo2: Box<Foo>) { 2 println!("{}", foo2.n); 3
} 4 fn main() { 5 let foo = boxed_foo(); 6 print_n(foo); 7 println!("{}", foo.n); 8 }
͜ΕίϯύΠϧΤϥʔʹͳΔ
ॴ༗ݖ (ownership) • ॴ༗ݖ = ͦͷΦϒδΣΫτΛղ์͢Δݖར • RustΦϒδΣΫτͷॴ༗ݖجຊతʹ1ͭͷ มʹଋറ͞ΕΔ •
ҧͨ͠߹ͯ͢ίϯύΠϧΤϥʔ
͜ͷ࣌ʹfoo͔Βॴ༗ݖফࣦ 1 fn print_n(foo2: Box<Foo>) { 2 println!("{}", foo2.n); 3
} 4 fn main() { 5 let foo = boxed_foo(); 6 print_n(foo); 7 println!("{}", foo.n); 8 } BEES OBNF WBM O ʜ GPP " GPP " BEES OBNF WBM " 'PP\O^ Stack heap ←call
0ͷྖҬͷΞΫηεېࢭ͞ ΕΔ 1 fn print_n(foo2: Box<Foo>) { 2 println!("{}", foo2.n);
3 } 4 fn main() { 5 let foo = boxed_foo(); 6 print_n(foo); 7 println!("{}", foo.n); 8 } BEES OBNF WBM O ʜ GPP " GPP " BEES OBNF WBM " 'PP\O^ Stack heap ←call
ίϯύΠϥ͕ݕʂ 1 fn print_n(foo2: Box<Foo>) { 2 println!("{}", foo2.n); 3
} 4 fn main() { 5 let foo = boxed_foo(); 6 print_n(foo); 7 println!("{}", foo.n); 8 } BEES OBNF WBM O ʜ GPP " GPP " BEES OBNF WBM " 'PP\O^ Stack heap ↑ҧ
͏̍͜ͷέʔε 1 struct Foo { 2 pub n: u32, 3
} 4 impl Foo { 5 fn new() -> Foo { 6 Foo { n: 42 } 7 } 8 } 9 fn main() { 10 let foo = Foo::new(); 11 let bar = foo; 12 println!("{}", foo.n); 13 }
͜ΕίϯύΠϧΤϥʔ 1 struct Foo { 2 pub n: u32, 3
} 4 impl Foo { 5 fn new() -> Foo { 6 Foo { n: 42 } 7 } 8 } 9 fn main() { 10 let foo = Foo::new(); 11 let bar = foo; 12 println!("{}", foo.n); 13 } ←͜͜Ͱॴ༗ݖͷҠৡ͕ൃੜ
ॴ༗ݖͷҠৡͱೖ • Rustʹ͓͚Δ `=` ͷҙຯʮೖʯͰͳ͘ɺ ʮҠৡʯ (*Copy TraitΛ࣮͍ͯ͠ͳ͍߹) • ॴ༗ݖ͕Ҡৡ͞Εͨޙͷม(foo)ʹର͢Δ
ૢ࡞ίϯύΠϥ͕ͯ͘͢
ࢀরͱआ༻ • Read Onlyͷࢀর Λି͚͠Δ͜ͱ͕ Ͱ͖Δ 1 fn print_n(foo: &Foo)
{ 2 println!("{}", foo.n); 3 } 4 fn main() { 5 let foo = Foo::new(); 6 let a = &foo; 7 let b = &foo; 8 let c = &foo; 9 print_n(a); 10 print_n(b); 11 print_n(c); 12 }
ϛϡʔλϒϧࢀর • WriteͰ͖Δࢀর # 1͔ͭ͠ିΒΕͳ͍ 1 fn print_n(foo: &mut Foo)
{ 2 foo.n = 100; 3 println!("{}", foo.n); 4 } 5 fn main() { 6 let mut foo = Foo::new(); 7 let a = &mut foo; 8 // let b = &mut foo; <= ͜ΕίϯύΠϧΤϥʔ 9 print_n(a); 10 }
आ༻ͱण໋ • आ༻ઌͷण໋ > आ༻ݩͷण໋ ίϯύΠϧΤϥʔ 1 fn main() {
2 let a; 3 { 4 let b = 100; 5 a = &b; 6 } 7 println!("{}", a); 8 }
৭ʑ • Lifetime Parameter ࢀরΛฦ͢ͱ͖ʹ໌ࣔ͢Δܕύϥϝʔλ • ৄ͘͠RustͷDocumentΛࢀর… • https://rust-lang-ja.github.io/the-rust- programming-language-ja/1.6/book/
ownership.html
RustͷԿ͕ྑ͍ͷ͔ • ॴ༗ݖγεςϜʹΑΔ҆શͳϝϞϦཧ ʢฒྻੑʹد༩ʣ • ϝϞϦ҆શɺσʔλڝ߹҆શΛͯ͢ ίϯύΠϥ͕νΣοΫͯ͘͠ΕΔ • (ଞʹ) ચ࿅͞ΕͨύλʔϯϚονΤϥʔॲ
ཧͳͲ
͔͜͜ΒRustΛͲΜͳͱ͜ Ζʹ׆༻͠Α͏ͱ͍ͯ͠Δ͔ ΛΓ·͢
Rustͷ׆༻Λߟ͑Δ • ߴεϧʔϓοτ͕ٻΊΒΕΔNetwork Middleware • CPU IntensiveͳॲཧΛߦ͏αʔό ྫ) ը૾ɾಈըͷEncoding Server
SSR༻ͷServer
ݱࡏݕূ͠Α͏ͱ͍ͯ͠Δͷ • ը૾ͷಈతมαʔό • http://hoge/w/200/h/200/kaicho.jpg original small
Event LoopͱCPU intensive • ҰൠతʹɺNode.jsCPU Intensiveͳॲཧʹ ͔ͳ͍ͱݴΘΕ͍ͯΔ • CPU IntensiveॲཧEvent
LoopΛετοϓ ͤͯ͞͠·͍ɺεϧʔϓοτΛԼͤͯ͞͠ ·͏ɻ
5ISFBE1PPM ʢԾઆʣطଘγεςϜͷ • Event LoopϞσϧͷαʔόʹCPU Intensiveͳ taskΛΈࠐΉ߹ɺEventLoopΛϒϩοΫ͢ ΔΑ͏ʹ࣮͞Ε͍ͯΔέʔε͕ଟ͘ɺεϧʔ ϓοτʹѱӨڹ 5BTL
5BTL &WFOU '4 #MPDLʂ
5ISFBE1PPM ॲཧͷΦϑϩʔυ • CPU intensiveͳॲཧBackendͷThread Pool Ϣʔβ͕໌ࣔతʹ͛ΒΕΔઃܭ 5BTL 5BTL &WFOU
'4
Proof of Concepts • tokio-minihttp + ImageMagick Ͱ ؆қը૾มαʔόΛߏங •
(tokio … RustͰඇಉظIOΛఏڙ͢ΔFW) • ImageMagickΛIO / ThreadͰ࣮ߦ͢Δύλʔϯͱ ผ్֬อ͞ΕͨThread PoolͰ࣮ߦ͢ΔύλʔϯͰ εϧʔϓοτΛܭଌ
ݕূڥ • Digital Ocean্ʹߏஙͨ͠Ubuntu (16.0.4.2) • rustc 1.18.0-nightly (1785bca51 2017-04-21)
• Core 2 or 4 • RAM 2GB / 4GB • ಉڥͷUbuntu͔ΒwrkͰୟ͘
݁Ռ (2core) 0 2.25 4.5 6.75 9 10 50 100
EV (2core) EV + MT (2core) ಉ࣌ଓ req/s
݁Ռ (4core) 0 6 12 18 24 10 50 100
EV (4core) EV + MT (4core) ಉ࣌ଓ req/s
ߟ • Event Loop Onlyͷͷಉ࣌ଓ্͕͕Δ ʹͭΕɺεϧʔϓοτ͕ݮগ͢Δ • Event Loop +
Multi-Threadͷ΄͏ଓʹ ର҆͠ఆ • Ծઆͷ࣮ূͷୈ̍า
Future Work • httpαʔόࣗମͷ࠶࣮ • gzipͳͲͷ࣮ • Cache etc… •
ͱΓ͋͑ͣ͋ͱ10ഒҎ্ૣ͘͠ͳ͚Ε ͑ͳ͍
Conclusion • Rustͷ͞ΘΓ • Heap / Stack • ॴ༗ݖγεςϜ •
RustΛ༻͍ͨը૾Τϯίʔυαʔόͷ։ൃ
Thank you for listening!