当前位置:网站首页>UE像素流,来颗“减肥药”吧!
UE像素流,来颗“减肥药”吧!
2022-07-05 08:13:00 【xosg】
Part1前言
像素流是虚幻引擎UE5提供的前后端分离框架:服务器运行UE5,前端渲染UI,中间传输视频流。这样,即使是无显卡的低端电脑或手机也能访问运行着UE5的服务器。
但是UE官方的像素流代码库非常臃肿,文档匮乏,难以直接使用,我们将其改造成轻量版的,开箱即用的像素流前端库以及信令服务器,地址:
https://github.com/inveta/peer-stream。
除此之外,我们还开发了与之配套的工具链,自动化监护像素流的生命周期,即使服务器无人管理也能正常运行。

Part2UE5自启动:飞快的启动速度
拜UE5的HLOD技术(Nanite以及WorldPartition)所赐,UE5打包程序启动时间基本在5s以内(即使是超大的模型),因此UE5没必要一直开在服务器上耗资源,网页访问的时候再临时启动,反正耽误不了几秒钟。在我们的开源库中,UE5自启动程序写在信令服务器中:当WebSocket有来自前端的新连接时,就启动UE5,无人访问时经过一段时间自动关闭UE5。
Part3单例模式:线程安全的文件锁
UE5自启动需要考虑线程安全的问题:如果前端有高并发的连接,很可能会启动多个UE5进程,那就给服务器带来巨大的压力。除此之外,运维人员如果不规范操作,也可能意外的打开多个UE5,导致系统崩溃。为了从根源上避免这个问题,我们开源了UE5单例模式插件:它严格限制了在同一台电脑上至多只能同时开启一个UE5实例,通过文件锁实现原子操作,非常稳定。
插件地址:https://github.com/inveta/SingleTon。

Part4UE5自动退出:节省系统资源
当没人看的时候,UE5自动关闭是理所应当的,但空闲关闭的超时时间需要设定在合理的区间内,时间设置既不能太短也不能太长:时间太短的话易发生频繁的启动与关闭,增加死机的风险;时间太长的话则形同虚设了,浪费系统资源。因此在合理的范围内,经过多次尝试,我们的像素流插件通过以下3种超时时间来控制UE5的生命周期,
● 信令服务器断开后10s内退出UE5:连信令服务器都挂了,UE5也就没有存在的必要了,但是为了防止短暂的中断,10s以内重连可以不用退出。
● 前端断开后,30分钟内退出UE5:用户关闭网页后,留30分钟观察期,期间若有新的网页连入,则停止计时器。
● UE5启动超过24小时后,退出UE5:有时候人不在电脑跟前,但浏览器保持着连接,导致UE5连续运行过长的时间,也会严重耗电,因此设定UE5最大运行时长为24小时。

Part5节流与防抖:最大程度预防崩溃
时间控制是像素流生态链中最不能忽视的细节,因为整个系统需要各种计时器来维护生命周期,处理异常状态,不同计时器的时间单位从毫秒到秒到分钟再到小时不等,除了上一节说到的3种UE5自动退出计时,为了节流和防抖,整个系统中还设定了以下8种计时器来应对可能的网络攻击。
● WebSocket断开后3s内自动重连:无需手动重连,也不立即重连。
● 初始化DataChannel请求延迟500ms:防止网页疯狂刷新。
● Dom元素断开后1s内不断开:防止前端JS代码不规范导致元素高频割接。
● 信令服务器500ms内至多建立1次WS连接:防止WebSocket崩溃。● 每50s发起一次WS心跳连接:避免代理服务器宕机。
● 信令服务器与UE5之间每分钟互发一次ping-pong保活请求。
● UE5每秒通过WebRTC向前端发送QP参数,监控网络状态和视频质量。
● 初始化时,UE5每秒向信令服务器发送10次WebSocket连接请求。
边栏推荐
- Semiconductor devices (I) PN junction
- Briefly talk about the identification protocol of mobile port -bc1.2
- Class of color image processing based on Halcon learning_ ndim_ norm. hdev
- Reasons for rapid wear of conductive slip rings
- Correlation based template matching based on Halcon learning [II] find_ ncc_ model_ defocused_ precision. hdev
- Communication standard -- communication protocol
- Gradle composite construction
- Sql Server的存储过程详解
- Define in and define out
- Design a clock frequency division circuit that can be switched arbitrarily
猜你喜欢

Altium designer learning (I)

Connection mode - bridge and net

Charge pump boost principle - this article will give you a simple understanding
![[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc](/img/9e/2524cbb9b90135c54669ba8d5338b7.jpg)
[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc

Arduino uses nrf24l01+ communication
![C WinForm [view status bar -- statusstrip] - Practice 2](/img/40/63065e6c4dc4e9fcb3e898981f518a.jpg)
C WinForm [view status bar -- statusstrip] - Practice 2

Interview catalogue

Compilation warning solution sorting in Quartus II

Classic application of MOS transistor circuit design (2) - switch circuit design

Volatile of C language
随机推荐
Compilation warning solution sorting in Quartus II
[untitled] record the visual shock of the Winter Olympics and the introduction of the display screen
Sizeof (function name) =?
Introduction of air gap, etc
Several implementation schemes of anti reverse connection protection of positive and negative poles of power supply!
Solutions to compilation warnings in Quartus II
Sql Server的存儲過程詳解
Talk about the circuit use of TVs tube
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine
[tutorial 15 of trio basic from introduction to proficiency] trio free serial communication
matlab timeserise
Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
PMSM dead time compensation
Record the torch encountered by win10 cuda. is_ False problem in available()
Fundamentals of C language
On boost circuit
Altium designer learning (I)
Naming rules for FreeRTOS
Hardware 3 -- function of voltage follower