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
20241120_JAWS_東京_ランチタイムLT#17_AWS認定全冠の先へ
tsumita
2
250
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
780
組織成長を加速させるオンボーディングの取り組み
sudoakiy
2
110
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
28
12k
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
4
1.4k
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
380
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
300
TypeScript、上達の瞬間
sadnessojisan
46
13k
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
ドメイン名の終活について - JPAAWG 7th -
mikit
33
20k
Featured
See All Featured
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
A better future with KSS
kneath
238
17k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
4 Signs Your Business is Dying
shpigford
180
21k
Designing for Performance
lara
604
68k
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!