winlin

fix #257, server latency is 0.1s+, the bottleneck is encoder. 2.0.71

@@ -786,6 +786,10 @@ The latency between encoder and player with realtime config( @@ -786,6 +786,10 @@ The latency between encoder and player with realtime config(
786 </tr> 786 </tr>
787 </table> 787 </table>
788 788
  789 +We use FMLE as encoder to benchmark. The latency of server is 0.1s+,
  790 +and the bottleneck is on the encoder. For more information, read
  791 +[bug #257](https://github.com/winlinvip/simple-rtmp-server/issues/257#issuecomment-66864413).
  792 +
789 ## Architecture 793 ## Architecture
790 794
791 SRS always use the most simple architecture to support complex transaction. 795 SRS always use the most simple architecture to support complex transaction.
@@ -589,11 +589,12 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsQueueRecvThread* trd) @@ -589,11 +589,12 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsQueueRecvThread* trd)
589 bool user_specified_duration_to_stop = (req->duration > 0); 589 bool user_specified_duration_to_stop = (req->duration > 0);
590 int64_t starttime = -1; 590 int64_t starttime = -1;
591 591
  592 + // setup the realtime.
  593 + realtime = _srs_config->get_realtime_enabled(req->vhost);
592 // setup the mw config. 594 // setup the mw config.
593 // when mw_sleep changed, resize the socket send buffer. 595 // when mw_sleep changed, resize the socket send buffer.
594 mw_enabled = true; 596 mw_enabled = true;
595 change_mw_sleep(_srs_config->get_mw_sleep_ms(req->vhost)); 597 change_mw_sleep(_srs_config->get_mw_sleep_ms(req->vhost));
596 - realtime = _srs_config->get_realtime_enabled(req->vhost);  
597 598
598 while (true) { 599 while (true) {
599 // to use isolate thread to recv, can improve about 33% performance. 600 // to use isolate thread to recv, can improve about 33% performance.
@@ -641,23 +642,6 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsQueueRecvThread* trd) @@ -641,23 +642,6 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsQueueRecvThread* trd)
641 srs_error("get messages from consumer failed. ret=%d", ret); 642 srs_error("get messages from consumer failed. ret=%d", ret);
642 return ret; 643 return ret;
643 } 644 }
644 -  
645 -#ifdef SRS_PERF_QUEUE_COND_WAIT  
646 - // we use wait timeout to get messages,  
647 - // for min latency event no message incoming,  
648 - // so the count maybe zero.  
649 - srs_info("mw wait %dms and got %d msgs %d(%"PRId64"-%"PRId64")ms",  
650 - mw_sleep, count,  
651 - (count > 0? msgs.msgs[count - 1]->timestamp - msgs.msgs[0]->timestamp : 0),  
652 - (count > 0? msgs.msgs[0]->timestamp : 0),  
653 - (count > 0? msgs.msgs[count - 1]->timestamp : 0));  
654 -#else  
655 - if (count <= 0) {  
656 - srs_info("mw sleep %dms for no msg", mw_sleep);  
657 - st_usleep(mw_sleep * 1000);  
658 - }  
659 -#endif  
660 - srs_info("got %d msgs, min=%d, mw=%d", count, SRS_PERF_MW_MIN_MSGS, mw_sleep);  
661 645
662 // reportable 646 // reportable
663 if (pithy_print.can_print()) { 647 if (pithy_print.can_print()) {
@@ -671,6 +655,29 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsQueueRecvThread* trd) @@ -671,6 +655,29 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsQueueRecvThread* trd)
671 ); 655 );
672 } 656 }
673 657
  658 + // we use wait timeout to get messages,
  659 + // for min latency event no message incoming,
  660 + // so the count maybe zero.
  661 + if (count > 0) {
  662 + srs_verbose("mw wait %dms and got %d msgs %d(%"PRId64"-%"PRId64")ms",
  663 + mw_sleep, count,
  664 + (count > 0? msgs.msgs[count - 1]->timestamp - msgs.msgs[0]->timestamp : 0),
  665 + (count > 0? msgs.msgs[0]->timestamp : 0),
  666 + (count > 0? msgs.msgs[count - 1]->timestamp : 0));
  667 + }
  668 +
  669 + if (count <= 0) {
  670 +#ifndef SRS_PERF_QUEUE_COND_WAIT
  671 + srs_info("mw sleep %dms for no msg", mw_sleep);
  672 + st_usleep(mw_sleep * 1000);
  673 +#else
  674 + srs_verbose("mw wait %dms and got nothing.", mw_sleep);
  675 +#endif
  676 + // ignore when nothing got.
  677 + continue;
  678 + }
  679 + srs_info("got %d msgs, min=%d, mw=%d", count, SRS_PERF_MW_MIN_MSGS, mw_sleep);
  680 +
674 // only when user specifies the duration, 681 // only when user specifies the duration,
675 // we start to collect the durations for each message. 682 // we start to collect the durations for each message.
676 if (user_specified_duration_to_stop) { 683 if (user_specified_duration_to_stop) {
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR 2 32 #define VERSION_MAJOR 2
33 #define VERSION_MINOR 0 33 #define VERSION_MINOR 0
34 -#define VERSION_REVISION 70 34 +#define VERSION_REVISION 71
35 // server info. 35 // server info.
36 #define RTMP_SIG_SRS_KEY "SRS" 36 #define RTMP_SIG_SRS_KEY "SRS"
37 #define RTMP_SIG_SRS_ROLE "origin/edge server" 37 #define RTMP_SIG_SRS_ROLE "origin/edge server"