Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lessons by WebAssembly app in production on CDN...

Lessons by WebAssembly app in production on CDN Edge Computing Service

Web Developer Conference 2024(Sept. 7th, 2024)https://web-study.connpass.com/event/321711/ にて発表のスライド。当日発表したものに加筆修正したもの。

Tetsuharu Ohzeki

September 10, 2024
Tweet

More Decks by Tetsuharu Ohzeki

Other Decks in Programming

Transcript

  1. Tetsuharu Ohzeki (github: tetsuharuohzeki) Lessons by WebAssembly app in production

    on CDN Edge Computing Service 1 Presented at September 7th, 2024
 slide ver. 2024.09.10.00
  2. About Me Tetsuharu OHZEKI • GitHub: tetsuharuohzeki • Software EngineerʢϑϦʔϥϯεɾcontractorʣʢ࢓ࣄઌ͸ެʹ͸ώϛπʣ

    • ΦʔϓϯιʔεతͳΞΫςΟϏςΟ • WebKit contributor (2020~) • Firefox/Gecko committer Lv.3ʢ͍͔ͭΒ͔๨Εͨʣ • Servo reviewer (େੲ) • ߩݙ͚ͩͳΒͦͷଞ৭ʑ΋ (RxJS, Node.js, TypeScript, and etc.) 2
  3. Introduction Please raise your hand if you…. 🙋 • WASM஌ͬͯΔ

    • WASMΛϗετ͢Δʢ࣮ߦ͢Δʣ؀ڥΛ࡞͍ͬͯΔ • WASMʹίϯύΠϧͯ͠ಈ͔͢ΞϓϦέʔγϣϯΛσϓϩΠͨ͜͠ͱ͕͋Δ • I am the member of Bytecode Alliance…… 3
  4. Goal of This session • WebAssembly 埋 込 動 厄介

    共有 • 厄介 減 必要 思 共有 • Wasm採 用 便利 5
  5. ⚠ Disclaimers • ࢲ͸Fastlyࣾͱ͸ޏ༻΍ۚમͳͲΛؚΉར֐ؔ܎͸͋Γ·ͤΜ • ؔ࿈͢Δ༗Ձূ݊౳ͷอ༗΋͍ͯ͠·ͤΜ • ຊηογϣϯ͸2024೥8݄ݱࡏͷެ։৘ใʹج͍ͮͨௐࠪ݁ՌʹࢲݟΛަ͑ͨ΋ͷ • Fastly

    ComputeͷՁ֨΍ੑೳʹؔ͢Δ࿩͸͠·ͤΜʢηʔϧεʹฉ͍ͯͶʂʣ • ෳ਺ɾڝ߹αʔϏεΛൺֱ͢Δͷ͕໨తͰ͸ͳ͍ • WebAssemblyͷṶ͚࿩΋஌Γ·ͤΜ 6 Fastly, Inc.ͱ͸ແؔ܎
  6. Outlines 1. Wasm͓ΑͼWASIͷجຊతͳ஌ࣝ 2. CDN Edge Computing Serviceͷ֓ཁɺ
 Fastly Computeͷ࣮ߦϞσϧͱ੍໿ͷެ։৘ใʹجͮ͘આ໌

    3. RustΛબ୒ͨ͠৔߹ͷWasmλʔήοτͳΞϓϦέʔγϣϯ։ൃͷ໽հ͞ 4. Wasm͸ຊ౰ʹʮۀքͷະདྷʯͰศརͳͷ͔ʁ
 ΞϓϦ։ൃऀ؍఺Ͱͷॴײͱఏݴ 7
  7. Outlines 1. Wasm͓ΑͼWASIͷجຊతͳ஌ࣝ 2. CDN Edge Computing Serviceͷ֓ཁɺ
 Fastly Computeͷ࣮ߦϞσϧͱ੍໿ͷެ։৘ใʹجͮ͘આ໌

    3. RustΛબ୒ͨ͠৔߹ͷWasmλʔήοτͳΞϓϦέʔγϣϯ։ൃͷ໽հ͞ 4. Wasm͸ຊ౰ʹʮۀքͷະདྷʯͰศརͳͷ͔ʁ
 ΞϓϦ։ൃऀ؍఺Ͱͷॴײͱఏݴ 8
  8. WebAssembly (WASM/Wasm) The new “sandboxed” execution format • ίϯύΠϧλʔήοτͰ͋ΔʢجຊతʹखͰॻ͘΋ͷͰ͸ͳ͍ʣ •

    asm.js΍NaCLͷޙܧ by W3C • Sandbox by default by design • ۩ମతͳhostcallɾ؀ڥͱ΍ΓͱΓ͢ΔAPI͸࢓༷ະఆٛ • ಠཱͨ͠ϑΥʔϚοτͳͷͰɺϓϥάΠϯ΍ϛυϧ΢ΣΞΛ࡞Δͷʹศར • e.g. Microsoft Flight Simulator, Proxy-Wasm 9
  9. WASI (WebAssembly System Interface) Wasm޲͚hostcallͷڞ௨ఆٛͷࢼΈ • hostcallఆٛͷڞ௨ԽΛ໨ࢦ͢ϕʔεϥΠϯͷҰͭ • By Bytecode

    Alliance • ڝ߹ʹWASIX by wasmer.ioͳΜͯ΋ͷ΋͋Δ͕লུ • Preview 1 • File descriptorͷ֓೦΍ཚ਺ੜ੒ɾ೔෇औಘͳͲɺPOSIXͬΆ͍΋ͷ͕ఆٛ͞Ε͍ͯΔ • Preview 2 • ίϯϙʔωϯτ֓೦ͷಋೖɾҟछݴޠؒίϯϙʔωϯτݺͼग़͠ن໿ɾIDLͷఆٛͳͲ 10
  10. WebAssembly Overview ͬ͘͟Γͨ͠ཧղ 12 WebAssembly hostcall ⚙ ⚙ ⚙ 🔊

    Embedder (host environment) ⏰ Host Features WASI p1
  11. WebAssembly Overview ͬ͘͟Γͨ͠ཧղ 13 WebAssembly hostcall ⚙ ⚙ ⚙ 🔊

    Embedder (host environment) ⏰ Host Features WASI p1 WASI p2 ⚙
  12. Key Points of This Section ͓͞Β͍ • WebAssembly = ໋ྩηοτɾίϯύΠϧλʔήοτ

    • C/C++ͳͲͰॻ͔Εͨطଘࢿ࢈ΛҠ২͢Δͷʹ࢖͑Δ • αϯυϘοΫεੑ͕ߴ͍ • ϗετଆ͸ׂͱࣗ༝ʹఆٛͰ͖Δ • ͨͩ͠WASIͳͲ֎෦࢓༷Ͱڞ௨Խ͕ࢼΈΒΕ͍ͯΔ • ϙʔλϏϦςΟ΍αϯυϘοΫεΛҙࣝͨ͠Ԡ༻͕૿Ճ 14
  13. Outlines 1. Wasm͓ΑͼWASIͷجຊతͳ஌ࣝ 2. CDN Edge Computing Serviceͷ֓ཁɺ
 Fastly Computeͷ࣮ߦϞσϧͱ੍໿ͷެ։৘ใʹجͮ͘આ໌

    3. RustΛબ୒ͨ͠৔߹ͷWasmλʔήοτͳΞϓϦέʔγϣϯ։ൃͷ໽հ͞ 4. Wasm͸ຊ౰ʹʮۀքͷະདྷʯͰศརͳͷ͔ʁ 
 ΞϓϦ։ൃऀ؍఺Ͱͷॴײ 15
  14. CDN Edge Computing Service ͬͯԿͩΑ • CDNͷEdgeʢ㲈Point of PresenceʣͰಈ࡞͢Δ೚ҙͷϓϩάϥϜΛσϓϩΠͰ͖ΔαʔϏεͷ͜ͱΛ ຊηογϣϯͰ͸ࢦ͢

    • ωοτϫʔΫϦΫΤετͷத਎ʹԠͨ͡৚݅෼ذΛϓϩάϥϜͰॻ͚Δͱࢥ͓͚ͬͯ͹OK • ϦόʔεϓϩΩγ΍HTTPϩʔυόϥϯαͷ૚ͰऔΕΔ৘ใ͕࢖͑Δ • ֓ͶHTTPϦΫΤετͱ1:1ͰΞϓϦέʔγϣϯΠϯελϯε্ཱ͕͕ͪΔαʔόʔϨεܕʹͳΔ • CDNࣄۀऀʹεέʔϥϏϦςΟ͸ؙ౤͛Ͱ͖Δ • ࣮ͨͩ͠ߦ؀ڥʹαʔϏεݻ༗ͷ੍໿͕ଟ͍ • e.g. Fastly Compute, Cloud fl are Worker, Vercel Function 16
  15. Fastly Compute ͬͯԿͩΑ • Fastlyࣾͷఏڙ͢ΔCDN Edge Computing Service • Previously,

    called as fastly Compute@Edge • WebAssemblyʹίϯύΠϧ͞ΕͨΞϓϦέʔγϣϯΛද޲͖ʹ͸௚ʹ࣮ߦ͢Δ • FastlyͷCDN Cacheͱ౷߹͞Ε͍ͯΔ • ͋Μ·ΓେྔͷܭࢉΛ΍Δͱޙड़ͷ੍ݶʹҾ͔͔ͬΔͷͰBFF༻్͕ओ • ಉࣾͷطଘͷઃఆํ๏ʢFastly VCLʣͱൺ΂ͯɺ
 ΋͏ͪΐ͍ݱ୅తɾ൚༻తͳϓϩάϥϛϯά͕ग़དྷΔͱ͍͏ҙຯͷ”Compute”ʁ 17
  16. F Fastly Compute: Execution Model • 1ͭͷHTTPϦΫΤετʹ͖ͭผʑͷΞϓϦέʔγϣϯΠϯελϯε͕
 ཱͬͯ͸ফ͑Δ • ຖճΠϯελϯεΛ࡞Γ௚͢ͷͰɺॳظԽίετΛ͍͔ʹ཈͑Δ͔͕ॏཁ

    • εϨου΍ϓϩηε֓೦͸ͳ͍ • Ϧιʔε͸ந৅ϋϯυϧΛܦ༝ͯ͠ѻ͏ 18 📱 💻 💻 📱 📱 📱 📱 💻 Wasm app Wasm app Wasm app Wasm app Wasm app Wasm app Wasm app Wasm app http http http http http http http Fastly ⚙ ⚙ ⚙ Origin Servers network req
  17. Fastly Compute: Default Limitations ΞϓϦέʔγϣϯ࣮ߦ؀ڥͱͯ͠ͷ੍໿ • ΞϓϦέʔγϣϯόΠφϦ1ͭ͋ͨΓ100MB • 1ϦΫΤετ͋ͨΓ •

    CPU࣌ؒ͸߹ܭ50ms • ࠷େ࣮ߦ࣌ؒ͸2min • ελοΫ1MBɾώʔϓ128MB • ؾ͕ͭ͘ͱ੍໿ͷઆ໌͕ࡉ͔͘ͳͬͯΔ 19 https://docs.fastly.com/products/compute-resource-limits
  18. Fastly Compute: SDK ։ൃ͢Δʹ͸ • Rust/JavaScript/Go͸Fasly੡ͷSDK͋Γ • Apache 2.0 LicenseʢLLVMྫ֎৚߲෇͖ʣͰϦϙδτϦ͕ެ։͞Ε͍ͯΔ

    • Rust͸ίʔυͷΈcrates.ioͰެ։ • Ruby΍Swift޲͚ͷSDK࣮૷΋ଘࡏ͢Δ • “community support” • ௕ظతʹͲ͏ͳΔ͔͸Α͘Θ͔ΒΜ • ͔ͳΓੲ͸AssemblyScriptͱ͔΋͚͋ͬͨͲdeprecated 20
  19. Fastly Compute: SDK Ϗϧυུ֓ • ݴޠͷίϯύΠϧλʔήοτΛWebAssemblyʹ͢ΔʢRust΍Go΍Swiftʣ • ݴޠඪ४ͷϥϯλΠϜϥΠϒϥϦؙ͝ͱWebAssemblyʹͯ͠ݻΊΔ • ॲཧܥͦͷ΋ͷΛWebAssmeblyԽͯ͠ɺͦͷ্ͰϓϩάϥϜΛ࣮ߦ͢ΔʢJS΍Rubyʣ

    • ͱ͸͍࣮͑ߦϞσϧతʹॳظԽίετͳͲ͕όΧʹͳΒͳ͍ • ݁ՌɺϏϧυޙʹॳظԽΛߦ͍ݻΊ௚͢πʔϧ͕ڬ·͍ͬͯΔ • https://github.com/fastly/js-compute-runtime • https://github.com/bytecodealliance/wizer 21
  20. Fastly Compute: Viceroy • ϩʔΧϧΤϛϡϨʔλʢViceroyʣ͕fastly͔Βఏڙ͞Ε͍ͯΔ • ΩϟογϡपΓΛআ͍ͯ؆қతͳಈ࡞ςετ͸Ͱ͖ΔͷͰɺࣗಈςετ͕࡞Ε Δ • ίʔυ΋ҰԠOpen

    SourceʢLLVMྫ֎৚߲෇͖Apache 2.0 Licenseʣʹ
 ͳ͍ͬͯΔ͕ɺ࣮؀ڥͷίʔυͷҰ෦Λ੾Γग़ͨ͠΋ͷͰ͸ͳ͍Β͍͠ • Wasm࣮ߦ෦෼͸wasmtime͕ڞ௨͍ͯ͠ΔͱࢥΘΕΔ͕ɺͦΕҎ֎͸ʁ • ޓ׵࣮૷Ͱ΋ɺڍಈΛ֬ೝ͢Δ্ͰhostcallΑΓ্૚͕ಡΊΔͷ͸௒ศར 22
  21. Fastly Compute: Wasm Binary Design • WASI + Fastlyઐ༻hostcall •

    RustͷSDKͱΤϛϡϨʔλಡΉͷ͕Ұ൪Θ͔Γ΍͍͢ • 2024೥9݄3೔ݱࡏͰ͸ɺද޲͖͸WASI preview 1ϕʔε • ͨͩɺޙड़ͷΤϛϡϨʔλʹ͸WASI preview 2ͷίϯϙʔωϯτϞσϧʹ
 ม׵͠௚͢ίʔυ͕͋Δ • কདྷతʹ͸σϓϩΠ࣌ظʹԠͯ͡ม׵͢ΔʁΑ͘Θ͔ΒΜ 23
  22. Key Points of This Section • CDN૚ͰϑϧϚωʔδυͳHTTPΞϓϦέʔγϣϯΛಈ͔͢FaaSΛ
 CDN Edge Computing

    Serviceͱศٓతʹݺশ • Fastly Compute͸WasmʹίϯύΠϧͨ͠ΞϓϦέʔγϣϯΛ
 ಈ͔ͤΔ • hostcall͸WASI + ಠ֦ࣗு • εέʔϥϏϦςΟͷͨΊ͔৭ʑ੍໿͕ଟ͍ 24
  23. Outlines 1. Wasm͓ΑͼWASIͷجຊతͳ஌ࣝ 2. CDN Edge Computing Serviceͷ֓ཁɺ
 Fastly Computeͷ࣮ߦϞσϧͱ੍໿

    3. RustΛબ୒ͨ͠৔߹ͷWasmλʔήοτͳΞϓϦέʔγϣϯ։ൃͷ໽հ͞ 4. Wasm͸ຊ౰ʹʮۀքͷະདྷʯͰศརͳͷ͔ʁ
 ΞϓϦ։ൃऀ؍఺Ͱͷॴײ 25
  24. Motivation & Background ͜Ε͔Βઆ໌͢Δܦݧஊͷલఏ • ։ൃର৅͸B2B޲͚ͷfastly VCLαʔϏε͔ΒͷҠߦ • ͔ͳΓσΧ͍VCLαʔϏε͕͍ͯɺͦΕ͔ΒͷҠߦ࣮ݧΛ݉ͶΔ •

    γεςϜ࠷લஈͰೝূपΓΛ֬ೝͭͭ͠ෳ਺ͷόοΫΤϯυΛதܧ͢Δ • ର৅ͷ։ൃӡ༻νʔϜͷୈ1ڞ௨ݴޠ͸JavaScript/TypeScript • ͳΜͰRustʁ 26
  25. Why Rust? (1) ศརͰָ͍͠ʂ͚ͩ͡Όͳ͍ • બఆ࣌ɺSDK͔Βར༻Ͱ͖Δػೳ͸Rust͕Ұ൪ଟ͔ͬͨ • Battery Included Toolchain

    • Compiler, Type Checker, Formatter, Lint, Unit TestingͳͲશ෦͍ͭͯ͘Δ • Deno͕͍͍ͱ͔Bun͕͍͍ͱ͔Rome͕͍͍ͱ͔ͦ͏͍͏࿩ΛճආͰ͖Δ • Rich Language Features • ໌ࣔతͳΤϥʔϋϯυϦϯάʹΑΔݎ࿚͞ • ύλʔϯϚονͱURLϧʔςΟϯάͷ૬ੑͷྑ͞ • ͚ͬ͜͏ڧྗͳ੩తܕ෇͚ 27
  26. Why Rust? (2) ඇػೳతͳظ଴ • ࣮ߦ؀ڥ੍໿Λߟ͑ΔͱϦιʔεফඅͷΦʔόʔϔουΛճආ͓͖͍ͯͨ͠ • GCͷແ͍ബ͍ϥϯλΠϜϥΠϒϥϦ૚ • ͨͩjs-computeͱ͔ݟͯΔͱᐜ༕ͩͬͨՄೳੑ΋͋Δ

    • Wasmʹ௚઀ίϯύΠϧͰ͖ΔϏϧυͷ୯७͞ • γϯάϧεϨου͔ͭྺ࢙తͳ༨ܭͳ΋ͷ͕গͳ͍࣮ߦ؀ڥͳͷͰɺ
 RustͷΊΜͲ͍͘͞ͱ͜ΖΛʢ֓ͶʣճආͰ͖Δ • Mutexͷॱংͱ͔ؾʹ͠ͳ͍͍ͯ͘ʂ 28
  27. But This Rust is different from your Rust উख͕ҧ͏ •

    ࢖͑Δcrate͕Α͘Θ͔ΒΜ • Կ͕࢖͑Δ͔͸exampleूΛோΊͯௐ΂Δ • ఆ൪framework͸ʢࠓ͸ͦͷ··ʣ࢖͑ͳ͍ • ग़ྗ͞ΕΔόΠφϦαΠζΛؾʹ͠ͳͯ͘͸ͳΒͳ͍ • ॳظԽίετΛݮΒͨ͢ΊʹίϯύΠϧ࣌ܭࢉΛ݁ߏҙࣝ͢Δ • ίετͷ͔͔Δڞ௨ॳظԽॲཧΛࡁ·͔ͤͯΒσϓϩΠ͢Δ͜ͱ͕Ͱ͖ͳ͍ͷͰ • Ͱ΋ݱঢ়ͷRustͷconst fn͸C++ 23ͷconstexprΑΓ΋੍໿͕ݫ͍͠ • Ͱ΋ݱঢ়ͷRust Generics͸C++ templateΈ͍ͨʹมͳ͜ͱ͕΍Γʹ͍͘ 29
  28. Build is little hard όΠφϦαΠζʹણࡉͳWebαʔόʔΞϓϦϓϩάϥϛϯά • ෆཁίʔυΛʢϏϧυ࣌ʹʣ࡟Εʂ • σόοάϏϧυ͸࿦֎ʢϦϦʔεϏϧυͩͱ20MBͳͷʹσόοάϏϧυͩ ͱ50MBͱ͔ʣ

    • ౰વɺ࢖ͬͯΔϥΠϒϥϦͷόʔδϣϯΛἧ͑Δͷ΋ॏཁ • όʔδϣϯҧ͍ͷಉ໊ϥΠϒϥϦ͕ґଘؔ܎ʹ͍ΔͱόΠφϦαΠζ͕૿͑ ΔͷͰ࡟Εʂ 31
  29. Build is little hard όΠφϦαΠζʹણࡉͳWebαʔόʔΞϓϦϓϩάϥϛϯά • LTOʢLink Time OptimizationʣΛ༗ޮʹͯ͠ແޮίʔυΛߋʹ࡟Δ
 ʢܦݧଇʹجͮ͘όουϊ΢ϋ΢ʣ

    • ϦϦʔεϏϧυͰ΋RustͷσϑΥϧτઃఆͩͱίʔυαΠζ͸࡟Εͳ͍͜ͱ͕͋Δ • ࣮༻্ɺThinLTOͰे෼ͳޮՌ͕ಘΒΕΔ • ͜Ε͚ͩͰग़ྗαΠζ͕20MB -> 10MBͱ͔ͷ੎͍Ͱ࡟ΕΔ • Rust 1.81ͰWasmు͘৔߹ɺLTOͳ͠ͷϏϧυ݁ՌΛ-OzΦϓγϣϯ෇͖ͷwasm- opt (github:WebAssembly/binaryen)ʹ౉͢ΑΓ΋ɺLTOΛ༗ޮʹ͢Δํ͕࡟ΕΔ 32
  30. Compile-time feature flag is complex Fastly CLIͷศརͳίϚϯυʹཔΕͳ͍ • Rustʹ͸ίϯύΠϧ࣌ϑΟʔνϟʔϑϥάͷ࢓૊Έ͕͋ΔͷͰ࢖͍͍ͨ •

    production/developmentͷ؀ڥͷҧ͍Λ෼͚Δ • ະ׬੒ίʔυ͸མͱ͍ͨ͠ • ΠϯΫϦϝϯλϧʹίʔυΛมߋ͍ͨ͠ • ……ͦͷͨΊʹ͸fastly CLIͷ”Easy”͔ͭall-in-oneʹϏϧυΛӅṭͯ͘͠ΕΔίϚϯ υ͸ແࢹ͢Δ • σϞ༻్ͩͱศར͚ͩͲɺCI༻్ʹ͸ඍົʹ࢖͍ʹ͍͘ 33
  31. Compile-time feature flag is complex Fastly CLIͷศརͳίϚϯυʹཔΕͳ͍ • fastly CLIʹ͸΋ͬͱ୯ػೳͳίϚϯυ΋͋ΔͷͰɺ


    ͦΕΒΛ࢖ͬͯࣗ෼ͰϏϧυγεςϜΛ૊ΈཱͯΔ • όΠφϦͷόϦσʔγϣϯͳͲ୯ػೳαϒίϚϯυʹ෼͔Ε͍ͯΔͷΛ࢖͏ • ͨͩυΩϡϝϯτͷղઆ͸ബ͍ͷͰɺ࣌ʑCLIͷιʔείʔυͱ
 ᛀΊ͕͍ͬ͜Δ 34
  32. Debugging is hard σόοΨͷΞλονʁͦ͜ʹͳ͚Ε͹ͳ͍Ͱ͢Ͷ • Wasmtime͸gdb/lldbΛΞλονͰ͖ΔΑ͏ʹͳ͍ͬͯΔ • ͔͠͠ΤϛϡϨʔλʢViceroyʣͰ͸ແޮʹ͞Ε͍ͯΔ • ༗ޮʹͯ͠Ξλον͢ΔͱΤϛϡϨʔλશମ͕ͳ͔ͥࢭ·Δ

    • ݪҼ͸ࠜਂͦ͏ͳͷͰ௥੻ͯ͠ͳ͍Ͱ͢ • ҰॠChrome Developer Tools ProtocolରԠ΋ೖΓͦ͏ʹͳ͚ͬͨͲɺ݁ہೖΒͳ͔ͬͨ • ΄΅printσόοάʹͳΔ • ελοΫτϨʔεͱࣗಈςετͰ໰୊ΛߜΓࠐΊʂ 35
  33. Unit Testing is hard ࢥͬͯͨ௨Γʹಈ͔ͳ͍ • RustͷϢχοτςετػߏΛ࢖ͬͯؔ਺୯ҐͷςετΛॻ͖͍ͨ৔߹ɺ
 fastly SDKϑϦʔͳcrateΛ༻ҙ͢Δඞཁ͕͋Δ •

    wasmϑΝΠϧ͸ʢී௨ʣͦͷ··࣮ߦͰ͖ͳ͍ • cargo-wasi-testͳΒwasmͷ··RustͷϢχοτςετΛ࣮ߦͰ͖Δ͕ɺ
 Fastlyݻ༗ͷhostcall͕ग़͖ͯͨॠؒɺunknown import errorͰࣦഊ͢Δ • ͜Ε͕݁ߏ௚ײʹ൓͢Δಈ͖Λ͢Δ • ࢓ํͳ͍ͷͰRustͷϢχοτςετػߏ͸ϓϥοτϑΥʔϜඇґଘͰ͋Δ͜ͱ͕
 ࣗ໌ͳՕॴ͚ͩ༻͍Δ͜ͱʹ…… 36
  34. Integration Testing is a little hard ݁ہ͜Ε͕Ұ൪ݎ࿚ • ౷߹ςετͷ࣮ߦʹ͸ςετϥϯφʔɾΤϛϡϨʔλɾ্ྲྀΞϓϦέʔγϣϯα ʔόʔͷڧௐಈ࡞͕ඞཁ

    • ࠓճͷέʔεͰ͸νʔϜڥքΛލ͙ɾґଘ͢Δ্ྲྀΞϓϦέʔγϣϯ͕ଟ͘
 ςετ্ཱ͕ͪ͛μϧ͍ • ۪௚ʹ΍ΔͱCI͕ॏް௕େʹͳͬͯ͠·͏ • ϩʔΧϧ࣮ߦ΋͖͍ͭ • ΞϓϦέʔγϣϯίϯςφҾͬு͖ͬͯͯdocker-compose͢Δ͸ෆ࠾༻ 38
  35. Integration Testing is a little hard ݁ہ͜Ε͕Ұ൪ݎ࿚ • αʔϏεڥք͕੹຿ڥքͰ͋Δ΂͖ͳͷͰɺ্ྲྀHTTPΞϓϦέʔγϣϯ͸
 શ෦ϞοΫͰ໰୊ͳ͍ͱ൑அ

    • ඞཁͳཁૉΛڠௐతʹ্ཱͪ͛ΔͨΊͷεʔύʔόΠβ͸Node.jsͰࣗ࡞ • νʔϜഎܠతʹςετϥϯφʔ΋ϞοΫαʔόʔ΋Node.js • CI্ཱͪ͛ͷ໰୊͸ղܾɻϩʔΧϧͰ΋࣮ߦ͕؆୯ʹɻ • ౷߹ςετΏ͑ɺ໢ཏੑΛ୲อ͢Δʹ͸ςετઃܭ͕ॏཁ • ૯౰ͨΓͷ݁ՌΛεφοϓγϣοτͯࠩ͠෼ൺֱ͢Δςετέʔε΋༗༻ 39
  36. Performance Optimization is a little hard ωοτϫʔΫI/O͕ࢧ഑తʹͳΓ͕ͪͳͷͰग़൪͕গͳ͍ͷ͕ශऑ͞ͷݪҼʁ • σϓϩΠޙ͸αʔϏεμογϡϘʔυͰ৭ʑϝτϦΫεݟΕΔ͕۩ମੑʹ͚ܽΔ •

    CPUϓϩϑΝΠϧ͸ΤϛϡϨʔλܦ༝ͰͰ͖Δ • https://pro fi ler. fi refox.com/ ʹ৯Θͤͯؾ߹͍ͰಡΉ • ϝϞϦϓϩϑΝΠϥ͸ΤϛϡϨʔλʹ΋ͳ͍ • ΤϛϡϨʔλ͕ϦΫΤετ͝ͱʹར༻ώʔϓ৘ใΛग़ͯ͘͠ΔͷͰצͰ୳Δ • CPUίετΑΓ΋ωοτϫʔΫίετͷ΄͏͕ଟ͍ΞϓϦͩͱ௚઀ͷग़൪͸গͳ͍͔΋ • ۩ମతʹࠔΔ·Ͱ͸ϩάͷॆ࣮ͱॲཧ۠ؒͷτϨʔγϯάͳͲΛؤுΔํ͕ྑͦ͞͏ 40
  37. Observability Instrumentation is hard (probably) ࠓճ͸ࠐΈೖͬͨ࿩͸Ͱ͖ͳ͍ • Server-Timing HTTP headerΛग़ྗ͢Δ͚ͩͳΒ؆୯

    • ࣮૷͢Ε͹͙͢Ͱ͖·͢ • OpenTelemetryͷinstrumentation͍ͨ͠৔߹͸େม͔΋͠Εͳ͍ • ࠓճͷέʔεͰ͸ͦ͜͸ະνϟϨϯδͳͷͰΑ͘Θ͔ΒΜ • tokio/hyperͷΤίγεςϜ͸ଟ෼ͦͷ··࢖͑ͳ͍ • JS SDKͩͱ݁ߏ؆୯ʹಋೖͰ͖ΔΒ͍͠ʁ • https://www.fastly.com/jp/blog/opentelemetry-part-3-using-opentelemetry-in-compute-edge/ 41
  38. Key Points of This Section • Rust͸WasmΛग़ྗ͢ΔͨΊͷDSLͱͯ͠΋ศར • ඇಉظI/Oͷͳ͍γϯάϧεϨουRust࠷ߴʢͦΕ͸Rust……ʁʣ •

    ࣮ͨͩ͠ߦ؀ڥͷ੍໿Ͱී௨ͷRustͱ͸ҟͳΔՕॴ΋ଟ͍ • ಛघͳ࣮ߦ؀ڥͰͷ։ൃʹ͸ΤϛϡϨʔλ͕ඞਢ • CIߏஙʹඞਢ • ͍ͭͰʹSDKͱΤϛϡϨʔλͷίʔυ͸खݩͷτϥγϡʔʹศརͳͷͰ
 Open Sourceʹͳ͍ͬͯͯ΄͍͠ 42
  39. Outlines 1. Wasm͓ΑͼWASIͷجຊతͳ஌ࣝ 2. CDN Edge Computing Serviceͷ֓ཁɺ
 Fastly Computeͷ࣮ߦϞσϧͱ੍໿ͷެ։৘ใʹجͮ͘આ໌

    3. RustΛબ୒ͨ͠৔߹ͷWasmλʔήοτͳΞϓϦέʔγϣϯ։ൃͷ໽հ͞ 4. Wasm͸ຊ౰ʹʮۀքͷະདྷʯͰศརͳͷ͔ʁ 
 ΞϓϦ։ൃऀ؍఺Ͱͷॴײͱఏݴ 43
  40. WebAssembly is Great ຒΊࠐ·ΕΔΞϓϦ։ൃऀ໨ઢ • ੩తʹίϯύΠϧ͞ΕͨόΠφϦΛσϓϩΠ͢ΔϞσϧ͸୯७͔ͭಁաతͰ޷͖ͩ • όΠτίʔυͷ࠷దԽҎ্ͷม׵͕͔͔Βͳ͍ɺ࢖͏ଆͷ҆৺ײ • hostcall͕ى఺ɾڥքͱͳΔͷͰ੹຿Λ෼͚ͯ௥͍΍͍͢

    • υΩϡϝϯτ΋Ζ͘ʹͳ͍ṖͷಠࣗDSLΑΓ͸ɺ
 ੍໿͕ಛघ͚ͩͲ޿͘ීٴͨ͠ߴਫ४ݴޠͰϓϩάϥϜΛॻ͚Δͷ͸ศར • όΠφϦϑΥʔϚοτͱͯ͠ͷ؆୯͞ • ྺ࢙తܦҢͷ༨ܭͳ΋ͷ͕ࠓͷॴͳ͍ 44
  41. But WebAssembly is nice (again) ຒΊࠐΉଆͷ໨ઢ • ৽نʹ੍ݶ෇͖ͷ೚ҙίʔυ࣮ߦͷ࢓૊ΈΛ࡞Δଆ͔Β͢Ε͹͍ͩͿ؆୯ • V8Ͱ΋wasmtimeͰ΋wasmerͰ΋ࣗ࡞Ͱ΋޷͖ͳͷΛͲ͏ͧ

    • θϩ͔ΒશͯΛ࡞Δඞཁ͕ͳ͍ • ࠔͬͨ࣌ʹϓϥάΠϯγεςϜΛ࡞Δ࣌ͷग़ൃ఺ • ཚ਺ੜ੒ͱ͔࣌ࠁऔಘͳͲͷ࠶ൃ໌ͨ͘͠ͳ͍ػೳ͸WASIΛࢀরͰ͖Δ • ΤίγεςϜͷؒआΓ͕ग़དྷΔ 47
  42. WebAssemblyΞϓϦ։ൃͷಛ௃ • ༑ਓʮWebAssembly͸૊ΈࠐΈ։ൃʹࣅ͍ͯΔʯ • QEMU΋ධՁϘʔυ΋γϦΞϧϙʔτ΋ཁΒͳ͍ߴϨΠϠʔͷ૊ΈࠐΈ • ΤϛϡϨʔλ͸͍ͭͩͬͯཉ͍͠͠ඞਢ • ΤϛϡϨʔλ͕͋Ε͹ࣗಈςετ΍CI͕࡞ΕΔ •

    CI࡞Γ΍͍͢ΤϛϡϨʔλͳΒঘخ͍͠ • ίʔυ΋ެ։͞ΕͯΔͱخ͍͠ • σόοΨαϙʔτ΋ཉ͍͠ • ΞϓϦέʔγϣϯίʔυઃܭ͸ɺςετ΍؀ڥ੍໿΁ͷద߹ʹڧؔ͘ΘΔ • ςετઃܭ΋ॏཁ • ΤϛϡϨʔλΛར༻ͨ͠౷߹ςετͷ໢ཏ཰ͳͲ 48