From cbad7a30748343be8f83523646708a65c20436a1 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 13 Dec 2014 12:48:49 +0800 Subject: [PATCH] fix #257, server latency is 0.1s+, the bottleneck is encoder. 2.0.71 --- README.md | 4 +++ trunk/src/app/srs_app_rtmp_conn.cpp | 43 +++++++++++++++++------------ trunk/src/core/srs_core.hpp | 2 +- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 64c3fdcb7..ec83eeb6b 100755 --- a/README.md +++ b/README.md @@ -786,6 +786,10 @@ The latency between encoder and player with realtime config( +We use FMLE as encoder to benchmark. The latency of server is 0.1s+, +and the bottleneck is on the encoder. For more information, read +[bug #257](https://github.com/winlinvip/simple-rtmp-server/issues/257#issuecomment-66864413). + ## Architecture SRS always use the most simple architecture to support complex transaction. diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index a7ce57427..a5666f64e 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -589,11 +589,12 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsQueueRecvThread* trd) bool user_specified_duration_to_stop = (req->duration > 0); int64_t starttime = -1; + // setup the realtime. + realtime = _srs_config->get_realtime_enabled(req->vhost); // setup the mw config. // when mw_sleep changed, resize the socket send buffer. mw_enabled = true; change_mw_sleep(_srs_config->get_mw_sleep_ms(req->vhost)); - realtime = _srs_config->get_realtime_enabled(req->vhost); while (true) { // to use isolate thread to recv, can improve about 33% performance. @@ -641,23 +642,6 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsQueueRecvThread* trd) srs_error("get messages from consumer failed. ret=%d", ret); return ret; } - -#ifdef SRS_PERF_QUEUE_COND_WAIT - // we use wait timeout to get messages, - // for min latency event no message incoming, - // so the count maybe zero. - srs_info("mw wait %dms and got %d msgs %d(%"PRId64"-%"PRId64")ms", - mw_sleep, count, - (count > 0? msgs.msgs[count - 1]->timestamp - msgs.msgs[0]->timestamp : 0), - (count > 0? msgs.msgs[0]->timestamp : 0), - (count > 0? msgs.msgs[count - 1]->timestamp : 0)); -#else - if (count <= 0) { - srs_info("mw sleep %dms for no msg", mw_sleep); - st_usleep(mw_sleep * 1000); - } -#endif - srs_info("got %d msgs, min=%d, mw=%d", count, SRS_PERF_MW_MIN_MSGS, mw_sleep); // reportable if (pithy_print.can_print()) { @@ -671,6 +655,29 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsQueueRecvThread* trd) ); } + // we use wait timeout to get messages, + // for min latency event no message incoming, + // so the count maybe zero. + if (count > 0) { + srs_verbose("mw wait %dms and got %d msgs %d(%"PRId64"-%"PRId64")ms", + mw_sleep, count, + (count > 0? msgs.msgs[count - 1]->timestamp - msgs.msgs[0]->timestamp : 0), + (count > 0? msgs.msgs[0]->timestamp : 0), + (count > 0? msgs.msgs[count - 1]->timestamp : 0)); + } + + if (count <= 0) { +#ifndef SRS_PERF_QUEUE_COND_WAIT + srs_info("mw sleep %dms for no msg", mw_sleep); + st_usleep(mw_sleep * 1000); +#else + srs_verbose("mw wait %dms and got nothing.", mw_sleep); +#endif + // ignore when nothing got. + continue; + } + srs_info("got %d msgs, min=%d, mw=%d", count, SRS_PERF_MW_MIN_MSGS, mw_sleep); + // only when user specifies the duration, // we start to collect the durations for each message. if (user_specified_duration_to_stop) { diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 3db2fb46f..0ea93eda5 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 2 #define VERSION_MINOR 0 -#define VERSION_REVISION 70 +#define VERSION_REVISION 71 // server info. #define RTMP_SIG_SRS_KEY "SRS" #define RTMP_SIG_SRS_ROLE "origin/edge server"