1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 11:51:57 +00:00

Support config to disable stat to improve performance.

This commit is contained in:
winlin 2020-04-16 18:37:37 +08:00
parent 810b32138e
commit 1a6e055f7f
5 changed files with 45 additions and 15 deletions

View file

@ -448,6 +448,9 @@ rtc_server {
# @remark The max padding size is 0x7f(127). # @remark The max padding size is 0x7f(127).
# default: 127 # default: 127
padding 127; padding 127;
# Whether enable the perf stat at http://localhost:1985/api/v1/perf
# default: off
perf_stat off;
} }
vhost rtc.vhost.srs.com { vhost rtc.vhost.srs.com {

View file

@ -3619,7 +3619,7 @@ srs_error_t SrsConfig::check_normal_config()
string n = conf->at(i)->name; string n = conf->at(i)->name;
if (n != "enabled" && n != "listen" && n != "dir" && n != "candidate" && n != "ecdsa" if (n != "enabled" && n != "listen" && n != "dir" && n != "candidate" && n != "ecdsa"
&& n != "sendmmsg" && n != "encrypt" && n != "reuseport" && n != "gso" && n != "merge_nalus" && n != "sendmmsg" && n != "encrypt" && n != "reuseport" && n != "gso" && n != "merge_nalus"
&& n != "padding") { && n != "padding" && n != "perf_stat") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal rtc_server.%s", n.c_str()); return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal rtc_server.%s", n.c_str());
} }
} }
@ -4858,6 +4858,23 @@ int SrsConfig::get_rtc_server_padding()
return srs_min(127, ::atoi(conf->arg0().c_str())); return srs_min(127, ::atoi(conf->arg0().c_str()));
} }
bool SrsConfig::get_rtc_server_perf_stat()
{
static bool DEFAULT = false;
SrsConfDirective* conf = root->get("rtc_server");
if (!conf) {
return DEFAULT;
}
conf = conf->get("perf_stat");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
SrsConfDirective* SrsConfig::get_rtc(string vhost) SrsConfDirective* SrsConfig::get_rtc(string vhost)
{ {
SrsConfDirective* conf = get_vhost(vhost); SrsConfDirective* conf = get_vhost(vhost);

View file

@ -537,6 +537,7 @@ private:
virtual bool get_rtc_server_gso2(); virtual bool get_rtc_server_gso2();
public: public:
virtual int get_rtc_server_padding(); virtual int get_rtc_server_padding();
virtual bool get_rtc_server_perf_stat();
public: public:
SrsConfDirective* get_rtc(std::string vhost); SrsConfDirective* get_rtc(std::string vhost);

View file

@ -1616,7 +1616,8 @@ srs_error_t SrsGoApiPerf::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
string target = r->query_get("target"); string target = r->query_get("target");
string reset = r->query_get("reset"); string reset = r->query_get("reset");
srs_trace("query target=%s, reset=%s", target.c_str(), reset.c_str()); srs_trace("query target=%s, reset=%s, rtc_stat_enabled=%d", target.c_str(), reset.c_str(),
_srs_config->get_rtc_server_perf_stat());
if (true) { if (true) {
SrsJsonObject* p = SrsJsonAny::object(); SrsJsonObject* p = SrsJsonAny::object();

View file

@ -686,6 +686,7 @@ srs_error_t SrsRtcSenderThread::cycle()
SrsPithyPrint* pprint = SrsPithyPrint::create_rtc_play(); SrsPithyPrint* pprint = SrsPithyPrint::create_rtc_play();
SrsAutoFree(SrsPithyPrint, pprint); SrsAutoFree(SrsPithyPrint, pprint);
bool stat_enabled = _srs_config->get_rtc_server_perf_stat();
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
while (true) { while (true) {
@ -729,17 +730,20 @@ srs_error_t SrsRtcSenderThread::cycle()
srs_freep(msg); srs_freep(msg);
} }
// Stat the original RAW AV frame, maybe h264+aac. // Stat for performance analysis.
stat->perf_on_msgs(msg_count); if (stat_enabled) {
// Stat the RTC packets, RAW AV frame, maybe h.264+opus. // Stat the original RAW AV frame, maybe h264+aac.
int nn_rtc_packets = srs_max(pkts.nn_audios, pkts.nn_extras) + pkts.nn_videos; stat->perf_on_msgs(msg_count);
stat->perf_on_rtc_packets(nn_rtc_packets); // Stat the RTC packets, RAW AV frame, maybe h.264+opus.
// Stat the RAW RTP packets, which maybe group by GSO. int nn_rtc_packets = srs_max(pkts.nn_audios, pkts.nn_extras) + pkts.nn_videos;
stat->perf_on_rtp_packets(pkts.size()); stat->perf_on_rtc_packets(nn_rtc_packets);
// Stat the RTP packets going into kernel. // Stat the RAW RTP packets, which maybe group by GSO.
stat->perf_on_gso_packets(pkts.nn_rtp_pkts); stat->perf_on_rtp_packets(pkts.size());
// Stat the bytes and paddings. // Stat the RTP packets going into kernel.
stat->perf_on_rtc_bytes(pkts.nn_bytes, pkts.nn_padding_bytes); stat->perf_on_gso_packets(pkts.nn_rtp_pkts);
// Stat the bytes and paddings.
stat->perf_on_rtc_bytes(pkts.nn_bytes, pkts.nn_padding_bytes);
}
#if defined(SRS_DEBUG) #if defined(SRS_DEBUG)
srs_trace("RTC PLAY perf, msgs %d/%d, rtp %d, gso %d, %d audios, %d extras, %d videos, %d samples, %d/%d bytes", srs_trace("RTC PLAY perf, msgs %d/%d, rtp %d, gso %d, %d audios, %d extras, %d videos, %d samples, %d/%d bytes",
msg_count, nn_rtc_packets, pkts.size(), pkts.nn_rtp_pkts, pkts.nn_audios, pkts.nn_extras, pkts.nn_videos, msg_count, nn_rtc_packets, pkts.size(), pkts.nn_rtp_pkts, pkts.nn_audios, pkts.nn_extras, pkts.nn_videos,
@ -1928,6 +1932,8 @@ srs_error_t SrsUdpMuxSender::cycle()
uint64_t nn_gso_msgs = 0; uint64_t nn_gso_iovs = 0; int nn_gso_msgs_max = 0; int nn_gso_iovs_max = 0; uint64_t nn_gso_msgs = 0; uint64_t nn_gso_iovs = 0; int nn_gso_msgs_max = 0; int nn_gso_iovs_max = 0;
int nn_loop = 0; int nn_wait = 0; int nn_loop = 0; int nn_wait = 0;
srs_utime_t time_last = srs_get_system_time(); srs_utime_t time_last = srs_get_system_time();
bool stat_enabled = _srs_config->get_rtc_server_perf_stat();
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
SrsPithyPrint* pprint = SrsPithyPrint::create_rtc_send(srs_netfd_fileno(lfd)); SrsPithyPrint* pprint = SrsPithyPrint::create_rtc_send(srs_netfd_fileno(lfd));
@ -1955,7 +1961,7 @@ srs_error_t SrsUdpMuxSender::cycle()
cache_pos = 0; cache_pos = 0;
// Collect informations for GSO. // Collect informations for GSO.
if (pos > 0) { if (pos > 0 && stat_enabled) {
// For shared GSO cache, stat the messages. // For shared GSO cache, stat the messages.
mmsghdr* p = &hotspot[0]; mmsghdr* end = p + pos; mmsghdr* p = &hotspot[0]; mmsghdr* end = p + pos;
for (p = &hotspot[0]; p < end; p++) { for (p = &hotspot[0]; p < end; p++) {
@ -1985,7 +1991,9 @@ srs_error_t SrsUdpMuxSender::cycle()
srs_warn("sendmmsg %d msgs, %d done", vlen, r0); srs_warn("sendmmsg %d msgs, %d done", vlen, r0);
} }
stat->perf_on_sendmmsg_packets(vlen); if (stat_enabled) {
stat->perf_on_sendmmsg_packets(vlen);
}
} }
} }