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
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
230
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
350
株式会社ログラス − エンジニア向け会社説明資料 / Loglass Comapany Deck for Engineer
loglass2019
3
32k
なぜCodeceptJSを選んだか
goataka
0
160
NilAway による静的解析で「10 億ドル」を節約する #kyotogo / Kyoto Go 56th
ytaka23
3
380
KnowledgeBaseDocuments APIでベクトルインデックス管理を自動化する
iidaxs
1
270
バクラクのドキュメント解析技術と実データにおける課題 / layerx-ccc-winter-2024
shimacos
2
1.1k
WACATE2024冬セッション資料(ユーザビリティ)
scarletplover
0
210
watsonx.ai Dojo #5 ファインチューニングとInstructLAB
oniak3ibm
PRO
0
170
AWS re:Invent 2024で発表された コードを書く開発者向け機能について
maruto
0
190
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
どちらを使う?GitHub or Azure DevOps Ver. 24H2
kkamegawa
0
840
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Bash Introduction
62gerente
608
210k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Code Review Best Practice
trishagee
65
17k
Building Applications with DynamoDB
mza
91
6.1k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
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!