-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cluster: K8s: Proxy to extend origin servers. #3138
Comments
frp 上的基础上改改 ? |
请问一下目前有哪些代理方案可以研究一下,拿来修改吗 |
更新进展:Proxy本质上是一个负载均衡问题,eBPF 比较合适实现。 另外,用 libbpf C++比较合适,而不是cilium/ebpf Go,两个差异挺大。 |
webrtc要给sdp,而lb后面的rs是不暴露的,好像没法解啊, |
ebpf太复杂了 我们目前实现, hls: pub -> lb1 -> srs -> pub hook -> go server -> save pub pod ip to mysql play -> lb2 -> go server -> get pod ip> get m3u8, ts from srs pod > return 缺点,依赖中心。依赖业务,go server加入的话,就是一个有点复杂的系统了. 有点,简单,短时间小流量绝对够用了,加个pod ip的local cache |
对于 rtmp 流转 webrtc 流的这种业务场景来说,由于 源站本身是有状态的,无法放到 K8S 上,目前我们的业务只能直接放在物理机上部署 是否可以考虑通过增加 这一层代理解决,源站的状态问题。 由于 proxy 这一层无状态,可以方便通过 deployment 部署, 向外暴露统一的 loadbalance 和域名 udp 的 LB,不会改写 udp 包的 源ip 和源 端口(https://exampleloadbalancer.com/nlbudp_detail.html) |
@qiantaossx Proxy就是这么设计的,会识别请求的内容,看客户端请求的是哪个流,然后再转发给后端服务器,所以可以用于所有协议的源站。 另外,关于源站有状态这事情,其实不用完全无状态也做不到,但可以通过重试的方式避免依赖。比如如果源站挂掉了,那么推流重试后,会选择新的源站,拉流重试后,也可以再次定位到这个新的源站。 这样源站和Proxy都可以无状态部署,做到非常简单的运维。 PS: 源站集群其实也是无状态的,只是因为目前的配置是需要一个地址,所以一般源站集群是Stateful,但如果改进下从一个API获取其他源站地址,那么其实也是无状态的。 PS: Proxy初步预计在SRS 6.0实现,估计从2023年初开始开发,有兴趣可以一起来参与。 |
最近看livekit,可以参考它的实现,pod会找到自己的对外地址(通过nat),然后将这个地址给sdp,这样就完成了集群webrtc源站分发 |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Both cluster and proxy works for system load balancing, in short to serve a large set of connections or clients, but there are some differences.
Cluster works as an integrity, a set of servers of a cluster works like one server. So it supports a large number of streams, and each stream supports a lots of connections. For example, a cluster supports 100k streams and 100m viewers, or infinety system capacity.
Proxy works as a agent of SRS Origin server, to proxy streams to a special set of origin servers, and proxy to the same server for a specifical stream. Proxy doesn't extend system capacity for it proxy each UDP or TCP packet, but it helps media server for load balancing.
Proxy is designed to make origin server stateless, to build a cluster from isolated stateless origin servers to a cluster, and can also be a part of a cluster.
Architecture
Proxy works with SRS Origin servers, the stream flow works like this:
LB
is load balancer, such as K8s service, or cloud load balancer. Generally,LB
binds public internet IP, for clients to connect to.Proxy is stateless, so you're able to deploy a set of proxy servers, for example, use K8s Deployment to deploy a set of proxies.
When client request stream from proxy server, it find stream from its infrastructure, and proxy to the specifical origin server, so that each stream is served by a specifical backend server. For the first time, proxy randomly pick one origin server for a fresh stream.
Service Discovery
Regarding service discovery, it involves two aspects: how the proxy discovers the origin servers and how the proxy obtains stream information from other proxy servers.
There are two types of service discovery mechanisms: one that caters to simple scenarios like demos or small clusters, and another that provides stability for large-scale online products.
In this architecture, both the proxy and origin servers, as well as the service manager, utilize the same HTTP API for service discovery, and the configuration file shares a consistent format across all components.
Proxy of Proxies
Edge is actually another type of proxy, but with origin ip configured, but origin pod IP is variant not fixed. While proxy doesn't need to configure the origin IP because it depends on redis or other service discover mechanism, so proxy can also be used for upstream server for edge. In this situation, proxy is like a K8s service of origin servers for edge servers.
With this architecture, we're able to support a huge set of streams and viewers, without origin cluster which is stateful and complex. Please note that edge only works for live streaming, such as RTMP/FLV. Other edge also works well, for example, HLS edge cluster works with Proxy, from where NGINX fetch and cache HLS. After WebRTC supports cascading, it also works with proxy.
Proxy Mirrors
To extend stream concurrency, proxy can mirror streams to multiple origin servers, to enable you to play stream from different origin server, for fault tolerance and scale out cluster capability.
For example, a RTC origin server could serve about 300 to 700 players for each stream, you can use proxy to mirror the same stream to 3 origin servers, to enable 900 to 2100 players.
Limitation
The limitation of proxy is the number of viewers for a stream, which should never exceed each single server's capacity, becuase proxy always proxy the same stream to the same backend server. For example, SRS support 5k viewers for RTMP/FLV, about 500 viewers for WebRTC, please test the capacity by srs-bench.
It's the responsibility of Cluster to support a large set of viewers, such as Edge Cluster for RTMP/FLV, or HLS Cluster for HLS. WebRTC doesn't support cluster now, please read wiki of WebRTC.
For most use scenario, Proxy is much simple and useful ability for load balancing, because there're a set of streams to serve but not too much, and there're also a set of viewers for each stream but not too much. For example, building a system for 1k streams and each stream has 1k viewers, the total connections of system is no more than 1m.
Proxy also works with cluster, for example, if you have 1k streams and each stream has 100k FLV viewers, the architecture is like this:
Keep in mind that proxy is design for Origin server, so there should always be proxy for a origin server, even for edge server to pull stream from. Proxy is another similar solution like origin cluster, but it's much simple and works for all protocols like RTMP/FLV/HLS/WebRTC/SRT, while origin cluster only works for RTMP.
Notes
Proxy should be written by Go/C++, stable and simple. Should be C++, because we might use eBPF.
It's possible to directly forward IP packets by kernel, to make proxy less CPU.
Proxy is much simpler than cluster, because both proxy and origin server is stateless, which can be deploy by K8s Deployment.
The text was updated successfully, but these errors were encountered: