From the wiki, the coworkers means "The HTTP APIs of other origin servers in the cluster". In our origin cluster, I config it like this:
vhost __defaultVhost__ {
# The config for cluster.
cluster {
# The cluster mode, local or remote.
# local: It's an origin server, serve streams itself.
# remote: It's an edge server, fetch or push stream to origin server.
# default: local
mode local;
# For origin(mode local) cluster, turn on the cluster.
# @remark Origin cluster only supports RTMP, use Edge to transmux RTMP to FLV.
# default: off
# TODO: FIXME: Support reload.
origin_cluster on;
# For origin (mode local) cluster, the co-worker's HTTP APIs.
# This origin will connect to co-workers and communicate with them.
# please read: https://github.com/ossrs/srs/wiki/v3_EN_OriginCluster
# TODO: FIXME: Support reload.
coworkers 192.168.1.101:1985 192.168.1.102:1985 192.168.1.103:1985 192.168.1.XXX:1985;
}
}
If there were thousands of SRS servers in the cluster, every SRS server should configure the lots of other origin SRS servers, is this right?
Is this affect the performance by query http api to find the right stream in which SRS server? If the stream is the last one in coworkers, I think it will have significant delay.
So I want to know, is there other best engineering practice to optimize this issue?
For OriginCluster, a set of origin works as a cluster to provide services to Edge server, like this:
OriginA+OriginB+OriginN ----RTMP(302)---> Edge server ---RTMP/FLV--> Client
So how does this work:
Origin servers use coworkers
in config, to find out the RIGHT server, which has the RTMP stream. The coworkers
actually is act as a service discovery, which is a HTTP server address.
The coworkers
is a HTTP server endpoint(ip+port), it could be SRS, or any HTTP servers, which provides the same HTTP API:
/api/v1/clusters
Response:
{
code: 0
data: {
origin: {
ip: 'xxx.xxx.xxx.xxx',
port: xxx
}
}
}
Please search
/api/v1/clusters
about the latest cluster protocol, it might be different.
If you got lots of streams and origin servers, you should never use SRS server as coworkers
, instead you should create a API server by Go or Nodejs whatever, only need to implements this API and config each origin server with this API:
vhost __defaultVhost__ {
cluster {
mode local;
origin_cluster on;
# Config for your API server.
coworkers 192.168.1.101:80;
}
}
Maybe your API server got one or two address for fault-tolerance.
How does your API server know about the streams? Please use HTTP Callback, it's also very simple.