Serverless 高密度部署与 Web-interoperable Runtime 在字节跳动的实践
如果无法正常显示,请先停止浏览器的去广告插件。
        
                相关话题:
                                    #字节跳动
                            
                        
                1. Serverless 高密度部署与
Web-interoperable Runtime
在字节跳动的实践
云原生与 W3C 的碰撞 / 朱凯迪(死月)
字节跳动-基础架构 架构师            
                        
                2.             
                        
                3. 朱凯迪(死月)
字节跳动/基础架构/架构师;Node.js Core Collaborator 之一;《Node.js:来一打
C++ 扩展》作者;《JavaScript 悟道》、《精通 Vim》译者。
•2013 - 2015 浙江大学 / 花瓣网
•2015 - 2017 大搜车
•2017 - 2021 阿里巴巴及蚂蚁集团
•2021 - 至今 字节跳动            
                        
                4. 大纲
<云原生>Serverless 高密度部署</云原生>
<W3C>Web-interoperable Runtime</W3C>
<实践>出真知</实践>
<理想要大>未来展望</理想要大>            
                        
                5. Serverless 高密度部署            
                        
                6. 老生常谈 Serverless
•
•
•
•
•
•
Low barrier-to-entry
Hostless
Stateless
Elasticity
Distributed
Event-driven            
                        
                7. 传统 Serverless            
                        
                8. ❤            
                        
                9. 二层调度与交付时间            
                        
                10. 二层调度与交付时间            
                        
                11. 二层调度与交付时间            
                        
                12. 二层调度与交付时间            
                        
                13. 二层调度与交付时间            
                        
                14. 二层调度与交付时间            
                        
                15. Serverless 冷启动            
                        
                16. Serverless 冷启动
几十秒            
                        
                17. Serverless 冷启动
几十秒
几秒            
                        
                18. Serverless 冷启动
几十秒
几秒
几百毫秒            
                        
                19. Serverless 冷启动因素            
                        
                20. Serverless 冷启动因素
• 设备性能            
                        
                21. Serverless 冷启动因素
• 设备性能
• 函数运行时            
                        
                22. Serverless 冷启动因素
• 设备性能
• 函数运行时
• 网络延迟            
                        
                23. Serverless 冷启动因素
•
•
•
•
设备性能
函数运行时
网络延迟
代码包(或者镜像)大小            
                        
                24. Serverless 冷启动因素
•
•
•
•
•
设备性能
函数运行时
网络延迟
代码包(或者镜像)大小
……            
                        
                25. Serverless 冷启动因素
•
•
•
•
•
设备性能
函数运行时
网络延迟
代码包(或者镜像)大小
……            
                        
                26. Serverless 冷启动因素
•
•
•
•
•
设备性能
函数运行时
网络延迟
代码包(或者镜像)大小
……
≈ 容器冷启动时间            
                        
                27. Serverless 冷启动影响            
                        
                28. Serverless 冷启动影响
Hostless            
                        
                29. Serverless 冷启动影响
Hostless
Stateless            
                        
                30. Serverless 冷启动影响
Hostless
Stateless
Elasticity            
                        
                31.             
                        
                32. 用 随
完 启
就 随
丢 停            
                        
                33. Serverless 冷启动优化
•
•
•
•
•
供应商:更换设备
供应商:提升网络架构
业务方:使用更轻量运行时,如 Node.js
业务方:合理组织函数代码,更轻量
……            
                        
                34. 运行时搞来搞去,还是要容器启动。            
                        
                35. 运行时搞来搞去,还是要容器启动。
有什么比容器更快?            
                        
                36. 进程(Process)            
                        
                37. 这不就是我吗?
进程(Process)            
                        
                38. 线程(Thread)            
                        
                39. 也有可能是我。
线程(Thread)            
                        
                40. 进程 vs 线程
(以 Web-interoperable Runtime 为例)
线程 进程
冷启动速度(可调度性) V8 Isolate 及相关环境初始化 进程启动、V8 Isolate 及相关环境初始化
资源隔离性(安全性) 同进程 Isolate 隔离 进程隔离
异常爆炸范围(稳定性) 进程崩溃会直接让所有 Isolate 挂掉;若池
化线程,则线程阻塞时影响较大 进程崩溃只影响单个函数、应用
云原生可扩展性(可玩性) 低 高            
                        
                41. 进程 vs 线程
(以 Web-interoperable Runtime 为例)
线程 进程
冷启动速度(可调度性) V8 Isolate 及相关环境初始化 进程启动、V8 Isolate 及相关环境初始化
资源隔离性(安全性) 同进程 Isolate 隔离 进程隔离
异常爆炸范围(稳定性) 进程崩溃会直接让所有 Isolate 挂掉;若池
化线程,则线程阻塞时影响较大 进程崩溃只影响单个函数、应用
云原生可扩展性(可玩性) 低 高            
                        
                42. 进程 vs 线程
(以 Web-interoperable Runtime 为例)
线程
√
进程
冷启动速度(可调度性) V8 Isolate 及相关环境初始化
进程启动、V8 Isolate 及相关环境初始化
资源隔离性(安全性) 同进程 Isolate 隔离 异常爆炸范围(稳定性) 进程崩溃会直接让所有 Isolate 挂掉;若池
化线程,则线程阻塞时影响较大 进程崩溃只影响单个函数、应用
云原生可扩展性(可玩性) 低 高
进程隔离            
                        
                43. 三层调度与交付时间            
                        
                44. 传统 Serverless            
                        
                45. 高密度部署 Serverless            
                        
                46. 高密度部署 Serverless
Pod            
                        
                47. ❤            
                        
                48. 三
层
调
度            
                        
                49. 三
层
调
度            
                        
                50. 低运维
什么?要我评估需要多少机器?多少资源?……算了,怎么大怎么来吧。            
                        
                51. 低运维
你不用估了,高密度全给你吃掉,反正我弹得快,资源利用粒度更细。            
                        
                52. 极端的资源利用率优化
1C2G × 6 × 20%
2C4G × 1 × 60%            
                        
                53. 如果……            
                        
                54. 如果……            
                        
                55. 如果……            
                        
                56. 如果……            
                        
                57. 如果……            
                        
                58. 如果……            
                        
                59. 如果……            
                        
                60. 如果……
Boom!            
                        
                61. 如果……
资源限制 / 资源隔离
Boom!            
                        
                62. 丨
Open Container Initiative            
                        
                63. 丨
Open Container Initiative
EaaI
Executable as an Image            
                        
                64. 丨
Open Container Initiative
EaaI PaaC
Executable as an Image Process as a Container            
                        
                65. r            
                        
                66.             
                        
                67.             
                        
                68. iku            
                        
                69. iku
资源限制 / 资源隔离            
                        
                70. Web-interoperator Runtime            
                        
                71. Web-interoperable Runtime?            
                        
                72. Web-interoperable Runtime?            
                        
                73. Web-interoperable Runtime?            
                        
                74. WinterCG
The Web-interoperable Runtimes Community Group (WinterCG)
is a community of people who are interested in using Web
Platform APIs outside of browsers, namely on the server (Deno /
Node.js) or edge runtimes.
The WinterCG is organized as a W3C Community Group. This
gives the group access to the W3C's vast infrastructure and its IPR
policy work. This is the same type of community that the WICG is
organized in.            
                        
                75.             
                        
                76. https://wintercg.org/            
                        
                77. https://wintercg.org/            
                        
                78. Interoperable: 互通性            
                        
                79. Interoperable: 互通性
大胆点:可相互替代、兼容            
                        
                80. Interoperable: 互通性
大胆点:可相互替代、兼容
(小声哔哔:各种浏览器之间就是 interoperable 的)            
                        
                81. Interoperable 前提: 标准化            
                        
                82. Interoperable 前提: 标准化            
                        
                83. Interoperable 前提: 标准化            
                        
                84. Interoperable 前提: 标准化
Common Minimum API            
                        
                85. Interoperable 前提: 标准化
Common Minimum API
The minimal collection of Web Platform APIs that ought to be implemented by Web-interoperable runtimes.            
                        
                86. Node.js?
也是。            
                        
                87. 市面上的 Winter
•
•
•
•
•
Node.js
Deno
CloudFlare Workers
Oxygen + Hydrogen
……            
                        
                88. 自研:Hourai.js            
                        
                89. 自研:Hourai.js
用于高密度部署            
                        
                90. Low barrier-to-entry            
                        
                91. Low barrier-to-entry
大基数下,JavaScripters 熟悉浏览器 API ≥ Node.js API            
                        
                92. Low barrier-to-entry
大基数下,JavaScripters 熟悉浏览器 API ≥ Node.js API            
                        
                93. Low barrier-to-entry
大基数下,JavaScripters 熟悉浏览器 API ≥ Node.js API
Web-interoperable Runtime! ?            
                        
                94. Hostless / Event-driven            
                        
                95. Hostless / Event-driven
Node.js 之写了整个 HTTP 服务端            
                        
                96. Hostless / Event-driven
Node.js 之 PM2、部署、运维……            
                        
                97. Hostless / Event-driven            
                        
                98. Hostless / Event-driven            
                        
                99. Hostless / Event-driven
Web-interoperable Runtime! Web-interoperable Runtime! ?            
                        
                100.             
                        
                101. 用 随
完 启
就 随
丢 停            
                        
                102. Stateless / Elasticity
轻量 / 启动速度快            
                        
                103. Stateless / Elasticity            
                        
                104. Stateless / Elasticity            
                        
                105. Stateless / Elasticity
≈ 200ms            
                        
                106. Stateless / Elasticity
≈ 200ms
得出数据的环境:macOS Monterey 12.0.1, MacBook Pro (16-inch, 2019), 2.6 GHz 六核 Intel Core i7, 32 GB 2667 MHz DDR4, Alacritty, ZSH            
                        
                107. Stateless / Elasticity            
                        
                108. Stateless / Elasticity
池化、snapshot……            
                        
                109. Stateless / Elasticity
池化、snapshot……
但为什么不直接……            
                        
                110. Stateless / Elasticity            
                        
                111. Stateless / Elasticity
iku 提供 ASSS 能力,专攻极速启动            
                        
                112. Stateless / Elasticity
iku 提供 ASSS 能力,专攻极速启动
Active Safety Strip Snapshot            
                        
                113. Stateless / Elasticity            
                        
                114. Stateless / Elasticity
冷启动速度
启动速度
Node.js Goofy Worker v1.0 Goofy Worker v2.0
(代号 Hourai.js)
≈200-300ms
≈60ms ≈10-15ms ? ≤1ms ≈0ms ?            
                        
                115. Stateless / Elasticity
冷启动速度
启动速度
Node.js Goofy Worker v1.0 Goofy Worker v2.0
(代号 Hourai.js)
≈200-300ms
≈60ms ≈10-15ms ? ≤1ms ≈0ms ?
Web-interoperable Runtime! Web-interoperable Runtime! Web-interoperable Runtime! ?            
                        
                116. 出真知            
                        
                117. 实践·一组数据
某服务迁移到线程级高密度部署(底层基于 Goofy Worker 1.0 的运行时),            
                        
                118. 高密度部署            
                        
                119. 高密度部署
高密度部署 = 更高的资源利用率 + 更快的调度速度 + 更低的运维成本            
                        
                120. 高密度部署
高密度部署 = 更高的资源利用率 + 更快的调度速度 + 更低的运维成本
智能的资源自适配算法            
                        
                121. 高密度部署
高密度部署 = 更高的资源利用率 + 更快的调度速度 + 更低的运维成本
智能的资源自适配算法
搭配亚毫秒启动 Winter            
                        
                122. 高密度部署
高密度部署 = 更高的资源利用率 + 更快的调度速度 + 更低的运维成本
智能的资源自适配算法
搭配亚毫秒启动 Winter
嫁接到我们自己身上了            
                        
                123. 实践·云原生· OpenTelemetry            
                        
                124. 实践·云原生· OpenTelemetry            
                        
                125. 实践·云原生· Dapr            
                        
                126. 实践·云原生· Dapr            
                        
                127. 可扩展
可适配各种 IaaS / FaaS 层,以应对不同场景。            
                        
                128. 实践·流程编排            
                        
                129. 高密度部署            
                        
                130. 高密度部署
高密度部署 = 更高的资源利用率 + 更快的调度速度 + 更低的运维成本            
                        
                131. 高密度部署
高密度部署 = 更高的资源利用率 + 更快的调度速度 + 更低的运维成本
智能的资源自适配算法            
                        
                132. 高密度部署
高密度部署 = 更高的资源利用率 + 更快的调度速度 + 更低的运维成本
智能的资源自适配算法
搭配亚毫秒启动 Winter            
                        
                133. 高密度部署
高密度部署 = 更高的资源利用率 + 更快的调度速度 + 更低的运维成本
智能的资源自适配算法
搭配亚毫秒启动 Winter
嫁接到我们自己身上了            
                        
                134. 实践·首屏速度
首屏时间的长短对于用户的滞留时间的长短、用户转化率都尤为重要。            
                        
                135. 实践·边缘 SSR (筹)            
                        
                136. 实践·边缘 SSR (筹)
= Modern.js × 边缘机房 × 高密度部署 × Web-interoperable Runtime            
                        
                137. 高密度部署            
                        
                138. 高密度部署
高密度部署 = 更高的资源利用率 + 更快的调度速度 + 更低的运维成本            
                        
                139. 高密度部署
高密度部署 = 更高的资源利用率 + 更快的调度速度 + 更低的运维成本
智能的资源自适配算法            
                        
                140. 高密度部署
高密度部署 = 更高的资源利用率 + 更快的调度速度 + 更低的运维成本
智能的资源自适配算法
搭配亚毫秒启动 Winter            
                        
                141. 高密度部署
高密度部署 = 更高的资源利用率 + 更快的调度速度 + 更低的运维成本
智能的资源自适配算法
搭配亚毫秒启动 Winter
嫁接到我们自己身上了            
                        
                142. 未来展望            
                        
                143. 展望·调度跃迁
1. K8S 直接穿透调度
2. 直接部署物理机,K8S 直接调度
3. K8S……????            
                        
                144. 展望·Hourai.js
1. 更极速的 ASSS 能力;
2. 分布式极速启动的能力;
3. 与社区一起推进 WinterCG 发展;
4. ToB?开源?……            
                        
                145.             
                        
                146. 字节跳动 - 基础架构 - EngProd Team            
                        
                147. 字节跳动 - 基础架构 - EngProd Team
https://
engprod.team            
                        
                148. 字节跳动 - 基础架构 - EngProd Team
DevOps / Codebase / CloudIDE / Serverless / Collaboration / Measure
https://
engprod.team            
                        
                149. • mailto:i@2333.moe
• https://xcoder.in
• https://GitHub.com/XadillaX            
                        
                150.             
                        
                151.