sre集群的方式有两种一种是forword类型的。一种是edge-origin类型的。后者比前者要复杂的多。就从比较难的开始分析。
有实现edge,首先得在配置文件中做配置。配置方式如下
这个配置里配置了实时模式,边缘模式(remote)
那么这个配置到了代码中是如何生效的呢?
这里面核心的类还是SrsSource,如果服务设置为边缘模式,这个类的角色,经历了从服务到客户端在到服务的转变,具体来看。
首先,如果一个客户端连接上了一个边缘节点,在走到发布了play命令后,服务器会有进入playing()函数,具体如下
int SrsRtmpConn::playing(SrsSource* source)
{
int ret = ERROR_SUCCESS;
// create consumer of souce.
SrsConsumer* consumer = NULL;
if ((ret = source->create_consumer(this, consumer)) != ERROR_SUCCESS) {
srs_error("create consumer failed. ret=%d", ret);
return ret;
}
在create_consumer函数里,除了创建一个consumer外,服务还会做一个判断,判断服务的模式是否是边缘节点模式,如果是,那么调用边缘节点的对应函数启动边缘节点。
int SrsSource::create_consumer(SrsConnection* conn, SrsConsumer*& consumer, bool ds, bool dm, bool dg)
{
.....
// for edge, when play edge stream, check the state
if (_srs_config->get_vhost_is_edge(_req->vhost)) {
// notice edge to start for the first client.
if ((ret = play_edge->on_client_play()) != ERROR_SUCCESS) {
srs_error("notice edge start play stream failed. ret=%d", ret);
return ret;
}
}
代码如上,控制权转

本文探讨了SRS集群中Edge-Origin两种模式,重点解析了更复杂的Edge模式。在配置文件中启用Edge模式后,核心类SrsSource的角色转变为服务到客户端再到服务的转换。当客户端连接并发布play命令时,服务器进入playing()函数,SrsReusableThread2变量确保类能自我维持,实现流量转向边缘服务器。
最低0.47元/天 解锁文章
1224

被折叠的 条评论
为什么被折叠?



