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
Cloudflrea Workersの紹介 / Introduce Cloudflare Wo...
Search
Tomohide Takao
June 27, 2019
Programming
0
300
Cloudflrea Workersの紹介 / Introduce Cloudflare Workers. ~Think about the Edge Side Rendering ~
Cloudflare Workersの紹介と、サービスを下支えする技術について。
FastlyのTerrariumとの思想の違いについても考察をまとめています。
Tomohide Takao
June 27, 2019
Tweet
Share
More Decks by Tomohide Takao
See All by Tomohide Takao
proxy-wasm-rust-sdkについて
dorayakikun
0
340
Rustを使うためにやったこと
dorayakikun
3
1k
Other Decks in Programming
See All in Programming
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
650
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
510
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
200
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
180
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
340
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
160
AWSのLambdaで PHPを動かす選択肢
rinchoku
2
300
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
160
nekko cloudにおけるProxmox VE利用事例
irumaru
3
460
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
Featured
See All Featured
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
1
110
Unsuck your backbone
ammeep
669
57k
Fireside Chat
paigeccino
34
3.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Navigating Team Friction
lara
183
15k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
GitHub's CSS Performance
jonrohan
1031
460k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
Transcript
JSConf EU XࢀՃใࠂ wasmฤ Cloudflare Workersͷհ NodeֶԂ34࣌ݶ 2019-06-27 Tomohide Takao
whoami • ߴඌ ल(͔͓ͨ ͱͻͰ) • ౦ژӺۙ߫Ͱ Node.js ͱ͔ॻ͍͍ͯ·͢ɻ •
͖ͳݴޠ Rust Ͱ͢ɻ • Wasmͷେ͖Ͱ͢ɻ • Twitter: @dorayaki_kun • GitHub: dorayakikun
ؓٳ
͜͜1ʙ2ͰWasmͷ͕૿͖͑ͯ·ͨ͠
JSConf EUྫ֎Ͱͳ͍Ͱ͢ ͜͜1ʙ2ͰWasmͷ͕૿͖͑ͯ·ͨ͠
Wasmʹؔ࿈ͨ͠ൃද • day1 • Let’s build a JavaScript Engine •
day2 • Simulating Sand: Building Interactivity With WebAssembly • JavaScript’s Journey to the Edge
Let’s build a JavaScript Engine • RustͷJavaScript • RustͷEnumpattern matchΛར༻ͯ͠ɺLexingʙ
Execution·ͰΛ࣮ • ൃදதͷσϞͰwasm-bindgenΛར༻ͯ͠ϒϥβ্Ͱ WasmԽͨ͠JSRuntimeΛಈ͔͍ͯ͠·ͨ͠ https://www.youtube.com/watch?v=_uD2pijcSi4 https://jason-williams.co.uk/building-a-js-interpreter-in-rust-part-1/#more-140 https://jason-williams.co.uk/building-a-js-interpreter-in-rust-part-2/#more-165
Simulating Sand: Building Interactivity With WebAssembly • ϒϥβήʔϜͷmodͱͯ͠WasmΛ࠾༻ͨ͠ • WasmΛ࠾༻ͨ͠എܠ
• SandboxԽ͞Ε͓ͯΓɺηʔϑςΟ • ͢Ͱʹ࣮༻Խ͞Ε͍ͯΔٕज़ • wasm-bindgen / wasm-packͷར༻͕༰қͩͬͨ https://2019.jsconf.eu/max-bittker/simulating-sand-building-interactivity-with-webassembly.html https://twitter.com/MaxBittker https://github.com/MaxBittker https://maxbittker.com/
JavaScript’s Journey to the Edge • طଘͷwebඳըઓུͱEdge Side Renderingͷհ •
Cloudflare Workers(+ workers.dev) & wranglerͷհ ࠓճ͜ͷൃදΛਂ۷Γ͍͖ͯ͠·͢
Webͷݱঢ়Λཧͯ͠ΈΔ
JavaScriptͷbyteαΠζ • ঃʑʹ͕࣮ͩ֬ʹ্ঢ͍ͯ͠Δ • ͜ͷ3ͰϞόΠϧ50%Ҏ্ϑΝΠϧαΠζ͕૿Ճ https://beta.httparchive.org/reports/state-of-javascript#bytesjs
TimeToInteractive • TTI9ඵҎ্ • ·͊·͍͊ https://beta.httparchive.org/reports/loading-speed#ttci
طଘͷઓུ • SSR + Cache • ॊೈͳରԠ͕Ͱ͖Δ • ҰํɺTime to
First Byte͕͍ • CSR + Cache • Time to First Byte͕͍ • ҰํɺFirst Contentful Paint͔ΒTime to Interactive ·Ͱϥά͕͋Δ https://developers.google.com/web/updates/2019/02/rendering-on-the-web
ͲͪΒͷઓུτϨʔυΦϑ ଞͷઓུͳ͍ͷ͔?
Edge Side Renderingͱ͍͏ ৽ͨͳઓུ
Edge Side Rendering • Τοδαʔό্ͰHTMLΛrendering • ΤοδαʔόͷಛੑΛੜ͔ͯ͠ɺ Time to First
ByteΛվળ • Τοδαʔό্Ͱrendering͢Δ͜ͱͰɺ Time to Interactive·Ͱͷ࣌ؒΛվળ • SSRͱCSRͷྑ͍ͱ͜औΓ͕Ͱ͖ΔΈ
ͦΜͳEdge Side Rendering Ͱ͖ΔαʔϏε͕… Cloudflare Workers
Cloudflare Workers • Cloudflare͕ॴ༗͢ΔΤοδαʔό্ͰserverlessΞϓϦ έʔγϣϯΛಈ࡞ͤ͞ΔαʔϏε • ίʔυͷσϓϩΠweb·ͨwranglerͰߦ͏ • ݱঢ়αϙʔτ͞Ε͍ͯΔݴޠJavaScript, Wasm(*)
*ެࣜͷTemplateͰRustͷྫ͕͋Δ͕ɺ࠷ޙWasmʹม͍ͯ͠Δ multithreadʹରԠ͍ͯ͠ͳ͍WasmΛͳͥରԠݴޠͱ͍ͯ͠Δ͔ޙड़ https://workers.cloudflare.com/
Cloudflare Workersͷཁૉٕज़ • V8: Isolates • ͳͥ࠾༻ͨ͠ͷ͔? • ҆શੑ͕อূ͞Εͳ͍ίʔυΛɺଞͷڥӨڹΛ༩͑ͣ ࣮ߦ͔ͨͬͨ͠
• ্ه࣮ݱͷͨΊʹ…v8:Isolatesͷ2ͭͷಛੑ͕࠷దͩͬͨ 1. ୯ҰϓϩηεͰ͍ͭ͘ͷisolate contextΛಈ͔ͤΔ 2. isolate contextΛγʔϜϨεʹΓସ͑ΒΕΔ https://blog.cloudflare.com/cloud-computing-without-containers/
ͦΕҎલʹݕ౼͞Εٕͨज़ • Lua • Sandboxʹ࣮ߦ͕Ͱ͖ͳ͍ͨΊݟૹΓ • k8sͳͲͷίϯςφڥ • ҎԼͷཧ༝͔ΒݟૹΓ •
͖ͪΜͱӡ༻͢Δͱ͓͕͔͔ۚΔ • εέʔϧՄೳ͕ͩɺ͞΄Ͳ༰қͰͳ͍
Isolatesͱ VM / Containerͷൺֱ • ҎԼͷ2ͭͷ؍Ͱൺֱ • Code Footprint •
Memory Usage
Code Footprint https://www.youtube.com/watch?v=MBndZddVQdw&feature=youtu.be&t=1025 0 2500 5000 7500 10000 Code Footprint
1 100 10000 VM Container Isolates
Memory Usage 0 250 500 750 1000 Memory Usage 5
100 1,000 VM Container Isolates
ͳͥWasmରԠ͍ͯ͠Δ? • IsolateϕʔεͷγεςϜͰɺ ίϯύΠϧࡁΈͷίʔυΛ࣮ߦͰ͖ͳ͍ • Ϗϧυ͕ඞཁͳطଘΞϓϦͷϙʔςΟϯάखஈͱͯ͠ WasmΛఏڙ͍ͯ͠Δ
wrangler • Cloudflare Workers༻ͷcliπʔϧ • Cloudflare WorkersͷϓϩδΣΫτ࡞Ϗϧυɺ publish͕Ͱ͖Δ • npm
install -g, cargo install͍ͣΕ͔ͰಋೖՄೳ https://github.com/cloudflare/wrangler
Terrariumͱͷൺֱ • Terrariumͱ? • Fastly͕ఏڙ͢ΔEdge Computing Platform • ઐ༻ͷWasmΛ༻ҙͯ͠ಈ࡞ͤ͞Δ •
ରԠ͍ͯ͠ΔͷC, Rust, Assembly Script • ཪଆͷΈͱͯ͠lucet(ϧηοτ)Λར༻͍ͯ͠Δ https://wasm.fastlylabs.com/docs
Terrariumͱͷൺֱ • Wasm͔͠ར༻Ͱ͖ͳ͍ • lucet෦ͰWASI(ϫζΟ)͕ར༻͞Ε͍ͯΔͷͰ ϨΠϠʔͷૢ࡞ఆ͍ͯͦ͠͏ • ಉ͡TerrariumσϓϩΠࢿ࢈ؒͰར༻Ͱ͖Δ Key Value
StoreΛ͍࣋ͬͯΔ
Terrariumͱͷൺֱ Terrarium Workers
Terrariumͱͷൺֱ • ಠࣗύοέʔδͷhttp_guestΛར༻͢Δඞཁ͕͋Δ • Workers୯७ͳServiceWorkerͷ࣮Ͱ ϋʔυϧ͍(ϑϩϯτΤϯυΤϯδχΞ؍Ͱ)
Edge Side Rendering ༗ޮͳͷ͔ • άϩʔόϧͳαʔϏεͷ߹ɺࢫຯ͕͋Γͦ͏ • ҰํͰԿΛΤοδαʔόʹͤ͞Δ͔ٞͷ༨͕͋Δ
Edge Side Rendering ༗ޮͳͷ͔ • άϩʔόϧͳαʔϏεͷ߹ɺࢫຯ͕͋Γͦ͏ • ҰํͰԿΛΤοδαʔόʹͤ͞Δ͔ٞͷ༨͕͋Δ Α͍͍ํ͋ͬͨΒɺڭ͍͑ͯͩ͘͞…
Thanks