mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine the kbps of server.
This commit is contained in:
parent
fbbe46d272
commit
8bf60895a9
5 changed files with 27 additions and 34 deletions
|
@ -92,6 +92,7 @@ public:
|
||||||
virtual void on_thread_stop();
|
virtual void on_thread_stop();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
* reset and start sample of bytes.
|
||||||
* when server to get the kbps of connection,
|
* when server to get the kbps of connection,
|
||||||
* it cannot wait the connection terminated then get the kbps,
|
* it cannot wait the connection terminated then get the kbps,
|
||||||
* it must sample the kbps every some interval, for instance, 9s to sample all connections kbps,
|
* it must sample the kbps every some interval, for instance, 9s to sample all connections kbps,
|
||||||
|
|
|
@ -122,12 +122,12 @@ public:
|
||||||
* to statistic the kbps of io.
|
* to statistic the kbps of io.
|
||||||
* itself can be a statistic source, for example, used for SRS bytes stat.
|
* itself can be a statistic source, for example, used for SRS bytes stat.
|
||||||
* there are two usage scenarios:
|
* there are two usage scenarios:
|
||||||
* 1. connections to calc kbps:
|
* 1. connections to calc kbps by sample():
|
||||||
* set_io(in, out)
|
* set_io(in, out)
|
||||||
* sample()
|
* sample()
|
||||||
* get_xxx_kbps().
|
* get_xxx_kbps().
|
||||||
* the connections know how many bytes already send/recv.
|
* the connections know how many bytes already send/recv.
|
||||||
* 2. server to calc kbps:
|
* 2. server to calc kbps by add_delta():
|
||||||
* set_io(NULL, NULL)
|
* set_io(NULL, NULL)
|
||||||
* for each connection in connections:
|
* for each connection in connections:
|
||||||
* add_delta(connections) // where connection is a IKbpsDelta*
|
* add_delta(connections) // where connection is a IKbpsDelta*
|
||||||
|
|
|
@ -745,8 +745,12 @@ void SrsServer::remove(SrsConnection* conn)
|
||||||
|
|
||||||
srs_info("conn removed. conns=%d", (int)conns.size());
|
srs_info("conn removed. conns=%d", (int)conns.size());
|
||||||
|
|
||||||
// resample the resource of specified connection.
|
// resample the kbps to collect the delta.
|
||||||
resample_kbps(conn);
|
conn->kbps_resample();
|
||||||
|
|
||||||
|
// add delta of connection to server kbps.,
|
||||||
|
// for next sample() of server kbps can get the stat.
|
||||||
|
kbps->add_delta(conn);
|
||||||
|
|
||||||
// all connections are created by server,
|
// all connections are created by server,
|
||||||
// so we free it here.
|
// so we free it here.
|
||||||
|
@ -862,8 +866,8 @@ int SrsServer::do_cycle()
|
||||||
srs_update_network_devices();
|
srs_update_network_devices();
|
||||||
}
|
}
|
||||||
if ((i % SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES) == 0) {
|
if ((i % SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES) == 0) {
|
||||||
srs_info("update network rtmp server info.");
|
srs_info("update network server kbps info.");
|
||||||
resample_kbps(NULL);
|
resample_kbps();
|
||||||
srs_update_rtmp_server((int)conns.size(), kbps);
|
srs_update_rtmp_server((int)conns.size(), kbps);
|
||||||
}
|
}
|
||||||
#ifdef SRS_AUTO_HTTP_PARSER
|
#ifdef SRS_AUTO_HTTP_PARSER
|
||||||
|
@ -1013,31 +1017,24 @@ void SrsServer::close_listeners(SrsListenerType type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsServer::resample_kbps(SrsConnection* conn, bool do_resample)
|
void SrsServer::resample_kbps()
|
||||||
{
|
{
|
||||||
// resample all when conn is NULL.
|
// collect delta from all clients.
|
||||||
if (!conn) {
|
for (std::vector<SrsConnection*>::iterator it = conns.begin(); it != conns.end(); ++it) {
|
||||||
for (std::vector<SrsConnection*>::iterator it = conns.begin(); it != conns.end(); ++it) {
|
SrsConnection* conn = *it;
|
||||||
SrsConnection* client = *it;
|
|
||||||
srs_assert(client);
|
|
||||||
|
|
||||||
// only resample, do resample when all finished.
|
// resample the kbps to collect the delta.
|
||||||
resample_kbps(client, false);
|
conn->kbps_resample();
|
||||||
}
|
|
||||||
|
|
||||||
kbps->sample();
|
// add delta of connection to server kbps.,
|
||||||
return;
|
// for next sample() of server kbps can get the stat.
|
||||||
|
kbps->add_delta(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// resample for connection.
|
// TODO: FXME: support all other connections.
|
||||||
conn->kbps_resample();
|
|
||||||
|
|
||||||
kbps->add_delta(conn);
|
// sample the kbps, get the stat.
|
||||||
|
kbps->sample();
|
||||||
// resample for server.
|
|
||||||
if (do_resample) {
|
|
||||||
kbps->sample();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
|
int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
|
||||||
|
|
|
@ -278,12 +278,9 @@ private:
|
||||||
*/
|
*/
|
||||||
virtual void close_listeners(SrsListenerType type);
|
virtual void close_listeners(SrsListenerType type);
|
||||||
/**
|
/**
|
||||||
* resample the server kbps.
|
* resample the server kbs.
|
||||||
* if conn is NULL, resample all connections delta, then calc the total kbps.
|
|
||||||
* @param conn, the connection to do resample the kbps. NULL to resample all connections.
|
|
||||||
* @param do_resample, whether resample the server kbps. always false when sample a connection.
|
|
||||||
*/
|
*/
|
||||||
virtual void resample_kbps(SrsConnection* conn, bool do_resample = true);
|
virtual void resample_kbps();
|
||||||
// internal only
|
// internal only
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1119,9 +1119,7 @@ void srs_api_dump_summaries(std::stringstream& ss)
|
||||||
<< __SRS_JFIELD_ORG("net_send_bytes", ns_bytes) << __SRS_JFIELD_CONT
|
<< __SRS_JFIELD_ORG("net_send_bytes", ns_bytes) << __SRS_JFIELD_CONT
|
||||||
<< __SRS_JFIELD_ORG("srs_sample_time", nrs->sample_time) << __SRS_JFIELD_CONT
|
<< __SRS_JFIELD_ORG("srs_sample_time", nrs->sample_time) << __SRS_JFIELD_CONT
|
||||||
<< __SRS_JFIELD_ORG("srs_recv_bytes", nrs->rbytes) << __SRS_JFIELD_CONT
|
<< __SRS_JFIELD_ORG("srs_recv_bytes", nrs->rbytes) << __SRS_JFIELD_CONT
|
||||||
<< __SRS_JFIELD_ORG("srs_recv_kbps", nrs->rkbps) << __SRS_JFIELD_CONT
|
|
||||||
<< __SRS_JFIELD_ORG("srs_send_bytes", nrs->sbytes) << __SRS_JFIELD_CONT
|
<< __SRS_JFIELD_ORG("srs_send_bytes", nrs->sbytes) << __SRS_JFIELD_CONT
|
||||||
<< __SRS_JFIELD_ORG("srs_send_kbps", nrs->skbps) << __SRS_JFIELD_CONT
|
|
||||||
<< __SRS_JFIELD_ORG("conn_sys", nrs->nb_conn_sys) << __SRS_JFIELD_CONT
|
<< __SRS_JFIELD_ORG("conn_sys", nrs->nb_conn_sys) << __SRS_JFIELD_CONT
|
||||||
<< __SRS_JFIELD_ORG("conn_sys_et", nrs->nb_conn_sys_et) << __SRS_JFIELD_CONT
|
<< __SRS_JFIELD_ORG("conn_sys_et", nrs->nb_conn_sys_et) << __SRS_JFIELD_CONT
|
||||||
<< __SRS_JFIELD_ORG("conn_sys_tw", nrs->nb_conn_sys_tw) << __SRS_JFIELD_CONT
|
<< __SRS_JFIELD_ORG("conn_sys_tw", nrs->nb_conn_sys_tw) << __SRS_JFIELD_CONT
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue