1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

fix #142, tcp stat slow bug, use /proc/net/sockstat instead, refer to 'ss -s'. 0.9.183.

This commit is contained in:
winlin 2014-08-02 09:54:21 +08:00
parent d5f03200a7
commit 721acc350a
5 changed files with 60 additions and 57 deletions

View file

@ -207,6 +207,7 @@ Supported operating systems and hardware:
* 2013-10-17, Created.<br/> * 2013-10-17, Created.<br/>
## History ## History
* v1.0, 2014-08-02, fix [#142](https://github.com/winlinvip/simple-rtmp-server/issues/142), fix tcp stat slow bug, use /proc/net/sockstat instead, refer to 'ss -s'. 0.9.183.
* v1.0, 2014-07-31, fix [#141](https://github.com/winlinvip/simple-rtmp-server/issues/141), support tun0(vpn network device) ip retrieve. 0.9.179. * v1.0, 2014-07-31, fix [#141](https://github.com/winlinvip/simple-rtmp-server/issues/141), support tun0(vpn network device) ip retrieve. 0.9.179.
* v1.0, 2014-07-27, support build on OSX(Darwin). 0.9.177 * v1.0, 2014-07-27, support build on OSX(Darwin). 0.9.177
* v1.0, 2014-07-27, api connections add udp, add disk iops. 0.9.176 * v1.0, 2014-07-27, api connections add udp, add disk iops. 0.9.176

View file

@ -68,6 +68,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_RUSAGE_RESOLUTION_TIMES // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_RUSAGE_RESOLUTION_TIMES
#define SRS_SYS_RUSAGE_RESOLUTION_TIMES 30 #define SRS_SYS_RUSAGE_RESOLUTION_TIMES 30
// update network devices info interval:
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES
#define SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES 30
// update rusage interval: // update rusage interval:
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_CPU_STAT_RESOLUTION_TIMES // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_CPU_STAT_RESOLUTION_TIMES
#define SRS_SYS_CPU_STAT_RESOLUTION_TIMES 30 #define SRS_SYS_CPU_STAT_RESOLUTION_TIMES 30
@ -88,10 +92,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES
#define SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES 90 #define SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES 90
// update network devices info interval:
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES
#define SRS_SYS_NETWORK_RTMP_SERVER_RESOLUTION_TIMES 90
SrsListener::SrsListener(SrsServer* server, SrsListenerType type) SrsListener::SrsListener(SrsServer* server, SrsListenerType type)
{ {
fd = -1; fd = -1;

View file

@ -781,7 +781,7 @@ SrsNetworkRtmpServer::SrsNetworkRtmpServer()
ok = false; ok = false;
sample_time = rbytes = sbytes = 0; sample_time = rbytes = sbytes = 0;
nb_conn_sys = nb_conn_srs = 0; nb_conn_sys = nb_conn_srs = 0;
nb_conn_sys_et = nb_conn_sys_tw = nb_conn_sys_ls = 0; nb_conn_sys_et = nb_conn_sys_tw = 0;
nb_conn_sys_udp = 0; nb_conn_sys_udp = 0;
} }
@ -812,88 +812,88 @@ enum {
void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps) void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)
{ {
SrsNetworkRtmpServer& r = _srs_network_rtmp_server; SrsNetworkRtmpServer& r = _srs_network_rtmp_server;
// reset total. int nb_socks = 0;
r.nb_conn_sys = 0; int nb_tcp4_hashed = 0;
int nb_tcp_orphans = 0;
int nb_tcp_tws = 0;
int nb_tcp_total = 0;
int nb_tcp_mem = 0;
int nb_udp4 = 0;
if (true) { if (true) {
FILE* f = fopen("/proc/net/tcp", "r"); FILE* f = fopen("/proc/net/sockstat", "r");
if (f == NULL) { if (f == NULL) {
srs_warn("open proc network tcp failed, ignore"); srs_warn("open proc network sockstat failed, ignore");
return; return;
} }
// ignore title. // ignore title.
static char buf[1024]; static char buf[1024];
fgets(buf, sizeof(buf), f); fgets(buf, sizeof(buf), f);
int nb_conn_sys_established = 0;
int nb_conn_sys_time_wait = 0;
int nb_conn_sys_listen = 0;
int nb_conn_sys_other = 0;
// @see: http://tester-higkoo.googlecode.com/svn-history/r14/trunk/Tools/iostat/iostat.c // @see: https://github.com/shemminger/iproute2/blob/master/misc/ss.c
while (fgets(buf, sizeof(buf), f)) { while (fgets(buf, sizeof(buf), f)) {
int st = 0; // @see: get_sockstat_line()
int ret = sscanf(buf, "%*s %*s %*s %2x\n", &st); if (strncmp(buf, "sockets: used ", 14) == 0) {
int ret = sscanf(buf, "%*s %*s %d\n", &nb_socks);
if (ret == 1) { srs_assert(ret == 1);
if (st == SYS_TCP_ESTABLISHED) { } else if (strncmp(buf, "TCP: ", 5) == 0) {
nb_conn_sys_established++; int ret = sscanf(buf, "%*s %*s %d %*s %d %*s %d %*s %d %*s %d\n",
} else if (st == SYS_TCP_TIME_WAIT) { &nb_tcp4_hashed, &nb_tcp_orphans, &nb_tcp_tws, &nb_tcp_total, &nb_tcp_mem);
nb_conn_sys_time_wait++; srs_assert(ret == 5);
} else if (st == SYS_TCP_LISTEN) { } else if (strncmp(buf, "UDP: ", 5) == 0) {
nb_conn_sys_listen++; int ret = sscanf(buf, "%*s %*s %d\n", &nb_udp4);
} else { srs_assert(ret == 1);
nb_conn_sys_other++;
}
}
if (ret == EOF) {
break;
} }
} }
r.nb_conn_sys = nb_conn_sys_established + nb_conn_sys_time_wait + nb_conn_sys_listen + nb_conn_sys_other;
r.nb_conn_sys_et = nb_conn_sys_established;
r.nb_conn_sys_tw = nb_conn_sys_time_wait;
r.nb_conn_sys_ls = nb_conn_sys_listen;
fclose(f); fclose(f);
} }
int nb_tcp_estab = 0;
if (true) { if (true) {
FILE* f = fopen("/proc/net/udp", "r"); FILE* f = fopen("/proc/net/snmp", "r");
if (f == NULL) { if (f == NULL) {
srs_warn("open proc network udp failed, ignore"); srs_warn("open proc network snmp failed, ignore");
return; return;
} }
// ignore title. // ignore title.
static char buf[1024]; static char buf[1024];
fgets(buf, sizeof(buf), f); fgets(buf, sizeof(buf), f);
// all udp is close state.
int nb_conn_sys_close = 0;
// @see: http://tester-higkoo.googlecode.com/svn-history/r14/trunk/Tools/iostat/iostat.c // @see: https://github.com/shemminger/iproute2/blob/master/misc/ss.c
while (fgets(buf, sizeof(buf), f)) { while (fgets(buf, sizeof(buf), f)) {
int st = 0; // @see: get_snmp_int("Tcp:", "CurrEstab", &sn.tcp_estab)
int ret = sscanf(buf, "%*s %*s %*s %2x\n", &st); // tcp stat title
if (strncmp(buf, "Tcp: ", 5) == 0) {
if (ret == EOF) { // read tcp stat data
break; if (!fgets(buf, sizeof(buf), f)) {
break;
}
// parse tcp stat data
if (strncmp(buf, "Tcp: ", 5) == 0) {
int ret = sscanf(buf, "%*s %*d %*d %*d %*d %*d %*d %*d %*d %d\n", &nb_tcp_estab);
srs_assert(ret == 1);
}
} }
nb_conn_sys_close++;
} }
r.nb_conn_sys += nb_conn_sys_close;
r.nb_conn_sys_udp = nb_conn_sys_close;
fclose(f); fclose(f);
} }
// @see: https://github.com/shemminger/iproute2/blob/master/misc/ss.c
// TODO: FIXME: ignore the slabstat, @see: get_slabstat()
if (true) {
// @see: print_summary()
r.nb_conn_sys = nb_tcp_total + nb_tcp_tws;
r.nb_conn_sys_et = nb_tcp_estab;
r.nb_conn_sys_tw = nb_tcp_tws;
r.nb_conn_sys_udp = nb_udp4;
}
if (true) { if (true) {
r.ok = true; r.ok = true;
@ -1113,7 +1113,6 @@ void srs_api_dump_summaries(std::stringstream& ss)
<< __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
<< __SRS_JFIELD_ORG("conn_sys_ls", nrs->nb_conn_sys_ls) << __SRS_JFIELD_CONT
<< __SRS_JFIELD_ORG("conn_sys_udp", nrs->nb_conn_sys_udp) << __SRS_JFIELD_CONT << __SRS_JFIELD_ORG("conn_sys_udp", nrs->nb_conn_sys_udp) << __SRS_JFIELD_CONT
<< __SRS_JFIELD_ORG("conn_srs", nrs->nb_conn_srs) << __SRS_JFIELD_ORG("conn_srs", nrs->nb_conn_srs)
<< __SRS_JOBJECT_END << __SRS_JOBJECT_END

View file

@ -595,11 +595,14 @@ public:
int skbps_5m; int skbps_5m;
// connections // connections
// @see: /proc/net/snmp
// @see: /proc/net/sockstat
int nb_conn_sys; int nb_conn_sys;
int nb_conn_sys_et; // established int nb_conn_sys_et; // established
int nb_conn_sys_tw; // time wait int nb_conn_sys_tw; // time wait
int nb_conn_sys_ls; // listen
int nb_conn_sys_udp; // udp int nb_conn_sys_udp; // udp
// retrieve from srs interface
int nb_conn_srs; int nb_conn_srs;
public: public:

View file

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version // current release version
#define VERSION_MAJOR "0" #define VERSION_MAJOR "0"
#define VERSION_MINOR "9" #define VERSION_MINOR "9"
#define VERSION_REVISION "182" #define VERSION_REVISION "183"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info. // server info.
#define RTMP_SIG_SRS_KEY "SRS" #define RTMP_SIG_SRS_KEY "SRS"