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
Node学園 25限 Introduction to Rust
Search
Akito0107
April 24, 2017
Technology
1.5k
6
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Node学園 25限 Introduction to Rust
Node学園 25限の発表資料です。
Akito0107
April 24, 2017
More Decks by Akito0107
See All by Akito0107
テスタビリティの高いGoのAPIサーバを開発しよう
akito0107
2
9k
TypeScriptのコマンドラインパーサー
akito0107
1
590
Starting TDD with Node.js
akito0107
3
6.1k
Other Decks in Technology
See All in Technology
あなたの知らないAmazon VPC Route Server/Amazon VPC Route Server you don't know about
masakiokuda
2
230
AI Made Us Faster at Solving the Wrong Problems
marceloancelmo
0
180
Snapshot Testing in Practice: Predictable and Reliable SwiftUI Views
fespinoza
0
140
オンラインゲームのシステム全体像 - コロプラ 2026年度 新卒研修
colopl
0
870
[AWS 秋のクラウドオペレーション祭り 2026]AWS DevOps Agentで変わるリリースと運用対応 ~リリース管理機能と Directed actions のご紹介~
furuton
4
1.1k
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
17
120k
OSC2026on_the-world-is-waiting-for-your-voice.pdf
naruoga
0
360
Incremental HTTP
kazuho
5
2.1k
脆弱性診断って、何をしているの? 〜弱点を見つけて、会社の改善につなげるまで〜
keeg
0
370
React Nativeでの OTA Updateって、 どう説明する?
ichiki1023
0
150
AI時代のAPI開発を加速する品質ガードレール / API Quality Guardrails in the AI Era
yokawasa
0
160
AI 時代の Azure エンジニアリング ~ 私たちは何を磨き、何を任せるのか ~
chack411
1
520
Featured
See All Featured
Marketing to machines
jonoalderson
1
5.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
260
The Limits of Empathy - UXLibs8
cassininazir
2
710
Tell your own story through comics
letsgokoyo
1
1.1k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
WENDY [Excerpt]
tessaabrams
14
40k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
490
Building AI with AI
inesmontani
PRO
1
1.3k
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!