正在显示
5 个修改的文件
包含
27 行增加
和
34 行删除
@@ -92,6 +92,7 @@ public: | @@ -92,6 +92,7 @@ public: | ||
92 | virtual void on_thread_stop(); | 92 | virtual void on_thread_stop(); |
93 | public: | 93 | public: |
94 | /** | 94 | /** |
95 | + * reset and start sample of bytes. | ||
95 | * when server to get the kbps of connection, | 96 | * when server to get the kbps of connection, |
96 | * it cannot wait the connection terminated then get the kbps, | 97 | * it cannot wait the connection terminated then get the kbps, |
97 | * it must sample the kbps every some interval, for instance, 9s to sample all connections kbps, | 98 | * it must sample the kbps every some interval, for instance, 9s to sample all connections kbps, |
@@ -122,12 +122,12 @@ public: | @@ -122,12 +122,12 @@ public: | ||
122 | * to statistic the kbps of io. | 122 | * to statistic the kbps of io. |
123 | * itself can be a statistic source, for example, used for SRS bytes stat. | 123 | * itself can be a statistic source, for example, used for SRS bytes stat. |
124 | * there are two usage scenarios: | 124 | * there are two usage scenarios: |
125 | -* 1. connections to calc kbps: | 125 | +* 1. connections to calc kbps by sample(): |
126 | * set_io(in, out) | 126 | * set_io(in, out) |
127 | * sample() | 127 | * sample() |
128 | * get_xxx_kbps(). | 128 | * get_xxx_kbps(). |
129 | * the connections know how many bytes already send/recv. | 129 | * the connections know how many bytes already send/recv. |
130 | -* 2. server to calc kbps: | 130 | +* 2. server to calc kbps by add_delta(): |
131 | * set_io(NULL, NULL) | 131 | * set_io(NULL, NULL) |
132 | * for each connection in connections: | 132 | * for each connection in connections: |
133 | * add_delta(connections) // where connection is a IKbpsDelta* | 133 | * add_delta(connections) // where connection is a IKbpsDelta* |
@@ -745,8 +745,12 @@ void SrsServer::remove(SrsConnection* conn) | @@ -745,8 +745,12 @@ void SrsServer::remove(SrsConnection* conn) | ||
745 | 745 | ||
746 | srs_info("conn removed. conns=%d", (int)conns.size()); | 746 | srs_info("conn removed. conns=%d", (int)conns.size()); |
747 | 747 | ||
748 | - // resample the resource of specified connection. | ||
749 | - resample_kbps(conn); | 748 | + // resample the kbps to collect the delta. |
749 | + conn->kbps_resample(); | ||
750 | + | ||
751 | + // add delta of connection to server kbps., | ||
752 | + // for next sample() of server kbps can get the stat. | ||
753 | + kbps->add_delta(conn); | ||
750 | 754 | ||
751 | // all connections are created by server, | 755 | // all connections are created by server, |
752 | // so we free it here. | 756 | // so we free it here. |
@@ -862,8 +866,8 @@ int SrsServer::do_cycle() | @@ -862,8 +866,8 @@ int SrsServer::do_cycle() | ||
862 | srs_update_network_devices(); | 866 | srs_update_network_devices(); |
863 | } | 867 | } |
864 | if ((i % SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES) == 0) { | 868 | if ((i % SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES) == 0) { |
865 | - srs_info("update network rtmp server info."); | ||
866 | - resample_kbps(NULL); | 869 | + srs_info("update network server kbps info."); |
870 | + resample_kbps(); | ||
867 | srs_update_rtmp_server((int)conns.size(), kbps); | 871 | srs_update_rtmp_server((int)conns.size(), kbps); |
868 | } | 872 | } |
869 | #ifdef SRS_AUTO_HTTP_PARSER | 873 | #ifdef SRS_AUTO_HTTP_PARSER |
@@ -1013,31 +1017,24 @@ void SrsServer::close_listeners(SrsListenerType type) | @@ -1013,31 +1017,24 @@ void SrsServer::close_listeners(SrsListenerType type) | ||
1013 | } | 1017 | } |
1014 | } | 1018 | } |
1015 | 1019 | ||
1016 | -void SrsServer::resample_kbps(SrsConnection* conn, bool do_resample) | 1020 | +void SrsServer::resample_kbps() |
1017 | { | 1021 | { |
1018 | - // resample all when conn is NULL. | ||
1019 | - if (!conn) { | ||
1020 | - for (std::vector<SrsConnection*>::iterator it = conns.begin(); it != conns.end(); ++it) { | ||
1021 | - SrsConnection* client = *it; | ||
1022 | - srs_assert(client); | ||
1023 | - | ||
1024 | - // only resample, do resample when all finished. | ||
1025 | - resample_kbps(client, false); | ||
1026 | - } | 1022 | + // collect delta from all clients. |
1023 | + for (std::vector<SrsConnection*>::iterator it = conns.begin(); it != conns.end(); ++it) { | ||
1024 | + SrsConnection* conn = *it; | ||
1025 | + | ||
1026 | + // resample the kbps to collect the delta. | ||
1027 | + conn->kbps_resample(); | ||
1027 | 1028 | ||
1028 | - kbps->sample(); | ||
1029 | - return; | 1029 | + // add delta of connection to server kbps., |
1030 | + // for next sample() of server kbps can get the stat. | ||
1031 | + kbps->add_delta(conn); | ||
1030 | } | 1032 | } |
1031 | 1033 | ||
1032 | - // resample for connection. | ||
1033 | - conn->kbps_resample(); | ||
1034 | - | ||
1035 | - kbps->add_delta(conn); | ||
1036 | - | ||
1037 | - // resample for server. | ||
1038 | - if (do_resample) { | ||
1039 | - kbps->sample(); | ||
1040 | - } | 1034 | + // TODO: FXME: support all other connections. |
1035 | + | ||
1036 | + // sample the kbps, get the stat. | ||
1037 | + kbps->sample(); | ||
1041 | } | 1038 | } |
1042 | 1039 | ||
1043 | int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) | 1040 | int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) |
@@ -278,12 +278,9 @@ private: | @@ -278,12 +278,9 @@ private: | ||
278 | */ | 278 | */ |
279 | virtual void close_listeners(SrsListenerType type); | 279 | virtual void close_listeners(SrsListenerType type); |
280 | /** | 280 | /** |
281 | - * resample the server kbps. | ||
282 | - * if conn is NULL, resample all connections delta, then calc the total kbps. | ||
283 | - * @param conn, the connection to do resample the kbps. NULL to resample all connections. | ||
284 | - * @param do_resample, whether resample the server kbps. always false when sample a connection. | 281 | + * resample the server kbs. |
285 | */ | 282 | */ |
286 | - virtual void resample_kbps(SrsConnection* conn, bool do_resample = true); | 283 | + virtual void resample_kbps(); |
287 | // internal only | 284 | // internal only |
288 | public: | 285 | public: |
289 | /** | 286 | /** |
@@ -1119,9 +1119,7 @@ void srs_api_dump_summaries(std::stringstream& ss) | @@ -1119,9 +1119,7 @@ void srs_api_dump_summaries(std::stringstream& ss) | ||
1119 | << __SRS_JFIELD_ORG("net_send_bytes", ns_bytes) << __SRS_JFIELD_CONT | 1119 | << __SRS_JFIELD_ORG("net_send_bytes", ns_bytes) << __SRS_JFIELD_CONT |
1120 | << __SRS_JFIELD_ORG("srs_sample_time", nrs->sample_time) << __SRS_JFIELD_CONT | 1120 | << __SRS_JFIELD_ORG("srs_sample_time", nrs->sample_time) << __SRS_JFIELD_CONT |
1121 | << __SRS_JFIELD_ORG("srs_recv_bytes", nrs->rbytes) << __SRS_JFIELD_CONT | 1121 | << __SRS_JFIELD_ORG("srs_recv_bytes", nrs->rbytes) << __SRS_JFIELD_CONT |
1122 | - << __SRS_JFIELD_ORG("srs_recv_kbps", nrs->rkbps) << __SRS_JFIELD_CONT | ||
1123 | << __SRS_JFIELD_ORG("srs_send_bytes", nrs->sbytes) << __SRS_JFIELD_CONT | 1122 | << __SRS_JFIELD_ORG("srs_send_bytes", nrs->sbytes) << __SRS_JFIELD_CONT |
1124 | - << __SRS_JFIELD_ORG("srs_send_kbps", nrs->skbps) << __SRS_JFIELD_CONT | ||
1125 | << __SRS_JFIELD_ORG("conn_sys", nrs->nb_conn_sys) << __SRS_JFIELD_CONT | 1123 | << __SRS_JFIELD_ORG("conn_sys", nrs->nb_conn_sys) << __SRS_JFIELD_CONT |
1126 | << __SRS_JFIELD_ORG("conn_sys_et", nrs->nb_conn_sys_et) << __SRS_JFIELD_CONT | 1124 | << __SRS_JFIELD_ORG("conn_sys_et", nrs->nb_conn_sys_et) << __SRS_JFIELD_CONT |
1127 | << __SRS_JFIELD_ORG("conn_sys_tw", nrs->nb_conn_sys_tw) << __SRS_JFIELD_CONT | 1125 | << __SRS_JFIELD_ORG("conn_sys_tw", nrs->nb_conn_sys_tw) << __SRS_JFIELD_CONT |
-
请 注册 或 登录 后发表评论