winlin

fix #217, remove timeout recv, support 7.5k+ 250kbps clients. 2.0.30.

@@ -445,11 +445,12 @@ Supported operating systems and hardware: @@ -445,11 +445,12 @@ Supported operating systems and hardware:
445 [CN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_SrsLibrtmp#publish-h264-raw-data), 445 [CN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_SrsLibrtmp#publish-h264-raw-data),
446 [EN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_EN_SrsLibrtmp#publish-h264-raw-data) 446 [EN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_EN_SrsLibrtmp#publish-h264-raw-data)
447 ) by srs-librtmp. 447 ) by srs-librtmp.
448 -1. Support [6k+ clients](https://github.com/winlinvip/simple-rtmp-server/issues/194), 4Gbps per process. 448 +1. Support [6k+ clients](https://github.com/winlinvip/simple-rtmp-server/issues/194), 3Gbps per process.
449 1. Suppport [English wiki](https://github.com/winlinvip/simple-rtmp-server/wiki/v1_EN_Home). 449 1. Suppport [English wiki](https://github.com/winlinvip/simple-rtmp-server/wiki/v1_EN_Home).
450 1. Research and simplify st, [bug #182](https://github.com/winlinvip/simple-rtmp-server/issues/182). 450 1. Research and simplify st, [bug #182](https://github.com/winlinvip/simple-rtmp-server/issues/182).
451 1. Support compile [srs-librtmp on windows](https://github.com/winlinvip/srs.librtmp), 451 1. Support compile [srs-librtmp on windows](https://github.com/winlinvip/srs.librtmp),
452 [bug #213](https://github.com/winlinvip/simple-rtmp-server/issues/213). 452 [bug #213](https://github.com/winlinvip/simple-rtmp-server/issues/213).
  453 +1. Support [7.5k+ clients](https://github.com/winlinvip/simple-rtmp-server/issues/217), 4Gbps per process.
453 1. [no-plan] Support <500ms latency, FRSC(Fast RTMP-compatible Stream Channel tech). 454 1. [no-plan] Support <500ms latency, FRSC(Fast RTMP-compatible Stream Channel tech).
454 1. [no-plan] Support RTMP 302 redirect [#92](https://github.com/winlinvip/simple-rtmp-server/issues/92). 455 1. [no-plan] Support RTMP 302 redirect [#92](https://github.com/winlinvip/simple-rtmp-server/issues/92).
455 1. [no-plan] Support multiple processes, for both origin and edge 456 1. [no-plan] Support multiple processes, for both origin and edge
@@ -482,6 +483,7 @@ Supported operating systems and hardware: @@ -482,6 +483,7 @@ Supported operating systems and hardware:
482 * 2013-10-17, Created.<br/> 483 * 2013-10-17, Created.<br/>
483 484
484 ## History 485 ## History
  486 +* v2.0, 2014-11-22, fix [#217](https://github.com/winlinvip/simple-rtmp-server/issues/217), remove timeout recv, support 7.5k+ 250kbps clients. 2.0.30.
485 * v2.0, 2014-11-21, srs-librtmp add rtmp prefix for rtmp/utils/human apis. 2.0.29. 487 * v2.0, 2014-11-21, srs-librtmp add rtmp prefix for rtmp/utils/human apis. 2.0.29.
486 * v2.0, 2014-11-21, refine examples of srs-librtmp, add srs_print_rtmp_packet. 2.0.28. 488 * v2.0, 2014-11-21, refine examples of srs-librtmp, add srs_print_rtmp_packet. 2.0.28.
487 * v2.0, 2014-11-20, fix [#212](https://github.com/winlinvip/simple-rtmp-server/issues/212), support publish audio raw frames. 2.0.27 489 * v2.0, 2014-11-20, fix [#212](https://github.com/winlinvip/simple-rtmp-server/issues/212), support publish audio raw frames. 2.0.27
@@ -700,6 +702,7 @@ Performance benchmark history, on virtual box: @@ -700,6 +702,7 @@ Performance benchmark history, on virtual box:
700 * 2014-11-12, SRS 2.0.14, 2700clients, 69%CPU, 59MB. 702 * 2014-11-12, SRS 2.0.14, 2700clients, 69%CPU, 59MB.
701 * 2014-11-12, SRS 2.0.14, 3500clients, 95%CPU, 78MB. 703 * 2014-11-12, SRS 2.0.14, 3500clients, 95%CPU, 78MB.
702 * 2014-11-13, SRS 2.0.15, 6000clients, 82%CPU, 203MB. (500 publishers). 704 * 2014-11-13, SRS 2.0.15, 6000clients, 82%CPU, 203MB. (500 publishers).
  705 +* 2014-11-22, SRS 2.0.30, 7500clients, 87%CPU, 320MB.
703 706
704 Latest benchmark(2014-07-12): 707 Latest benchmark(2014-07-12):
705 708
@@ -388,7 +388,8 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then @@ -388,7 +388,8 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
388 "srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config" 388 "srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config"
389 "srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks" 389 "srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks"
390 "srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge" 390 "srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge"
391 - "srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_avc_aac") 391 + "srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_avc_aac"
  392 + "srs_app_recv_thread")
392 APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh 393 APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
393 APP_OBJS="${MODULE_OBJS[@]}" 394 APP_OBJS="${MODULE_OBJS[@]}"
394 fi 395 fi
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#include <srs_app_recv_thread.hpp>
  25 +
  26 +#include <srs_protocol_rtmp.hpp>
  27 +#include <srs_protocol_stack.hpp>
  28 +
  29 +SrsRecvThread::SrsRecvThread(SrsRtmpServer* rtmp_sdk)
  30 +{
  31 + rtmp = rtmp_sdk;
  32 + trd = new SrsThread(this, 0, true);
  33 +}
  34 +
  35 +SrsRecvThread::~SrsRecvThread()
  36 +{
  37 + // stop recv thread.
  38 + stop();
  39 +
  40 + // destroy the thread.
  41 + srs_freep(trd);
  42 +
  43 + // clear all messages.
  44 + std::vector<SrsMessage*>::iterator it;
  45 + for (it = queue.begin(); it != queue.end(); ++it) {
  46 + SrsMessage* msg = *it;
  47 + srs_freep(msg);
  48 + }
  49 + queue.clear();
  50 +}
  51 +
  52 +bool SrsRecvThread::empty()
  53 +{
  54 + return queue.empty();
  55 +}
  56 +
  57 +SrsMessage* SrsRecvThread::pump()
  58 +{
  59 + srs_assert(!queue.empty());
  60 +
  61 + SrsMessage* msg = *queue.begin();
  62 +
  63 + queue.erase(queue.begin());
  64 +
  65 + return msg;
  66 +}
  67 +
  68 +int SrsRecvThread::start()
  69 +{
  70 + return trd->start();
  71 +}
  72 +
  73 +void SrsRecvThread::stop()
  74 +{
  75 + trd->stop();
  76 +}
  77 +
  78 +int SrsRecvThread::cycle()
  79 +{
  80 + int ret = ERROR_SUCCESS;
  81 +
  82 + SrsMessage* msg = NULL;
  83 +
  84 + if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) {
  85 + if (!srs_is_client_gracefully_close(ret)) {
  86 + srs_error("recv client control message failed. ret=%d", ret);
  87 + }
  88 +
  89 + // we use no timeout to recv, should never got any error.
  90 + trd->stop_loop();
  91 +
  92 + return ret;
  93 + }
  94 + srs_verbose("play loop recv message. ret=%d", ret);
  95 +
  96 + return ret;
  97 +}
  98 +
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#ifndef SRS_APP_RECV_THREAD_HPP
  25 +#define SRS_APP_RECV_THREAD_HPP
  26 +
  27 +/*
  28 +#include <srs_app_recv_thread.hpp>
  29 +*/
  30 +
  31 +#include <srs_core.hpp>
  32 +
  33 +#include <vector>
  34 +
  35 +#include <srs_app_thread.hpp>
  36 +
  37 +class SrsRtmpServer;
  38 +class SrsMessage;
  39 +
  40 +/**
  41 +* the recv thread used to replace the timeout recv,
  42 +* which hurt performance for the epoll_ctrl is frequently used.
  43 +* @see: SrsRtmpConn::playing
  44 +* @see: https://github.com/winlinvip/simple-rtmp-server/issues/217
  45 +*/
  46 +class SrsRecvThread : public ISrsThreadHandler
  47 +{
  48 +private:
  49 + SrsThread* trd;
  50 + SrsRtmpServer* rtmp;
  51 + std::vector<SrsMessage*> queue;
  52 +public:
  53 + SrsRecvThread(SrsRtmpServer* rtmp_sdk);
  54 + virtual ~SrsRecvThread();
  55 +public:
  56 + virtual bool empty();
  57 + virtual SrsMessage* pump();
  58 +public:
  59 + virtual int start();
  60 + virtual void stop();
  61 + virtual int cycle();
  62 +};
  63 +
  64 +#endif
  65 +
@@ -48,6 +48,7 @@ using namespace std; @@ -48,6 +48,7 @@ using namespace std;
48 #include <srs_app_utility.hpp> 48 #include <srs_app_utility.hpp>
49 #include <srs_protocol_msg_array.hpp> 49 #include <srs_protocol_msg_array.hpp>
50 #include <srs_protocol_amf0.hpp> 50 #include <srs_protocol_amf0.hpp>
  51 +#include <srs_app_recv_thread.hpp>
51 52
52 // when stream is busy, for example, streaming is already 53 // when stream is busy, for example, streaming is already
53 // publishing, when a new client to request to publish, 54 // publishing, when a new client to request to publish,
@@ -493,76 +494,6 @@ int SrsRtmpConn::check_vhost() @@ -493,76 +494,6 @@ int SrsRtmpConn::check_vhost()
493 return ret; 494 return ret;
494 } 495 }
495 496
496 -class IsolateRecvThread : public ISrsThreadHandler  
497 -{  
498 -private:  
499 - SrsThread* trd;  
500 - SrsRtmpServer* rtmp;  
501 - std::vector<SrsMessage*> queue;  
502 -public:  
503 - IsolateRecvThread(SrsRtmpServer* rtmp_sdk)  
504 - {  
505 - rtmp = rtmp_sdk;  
506 - trd = new SrsThread(this, 0, true);  
507 - }  
508 - virtual ~IsolateRecvThread()  
509 - {  
510 - // stop recv thread.  
511 - stop();  
512 -  
513 - // destroy the thread.  
514 - srs_freep(trd);  
515 -  
516 - // clear all messages.  
517 - std::vector<SrsMessage*>::iterator it;  
518 - for (it = queue.begin(); it != queue.end(); ++it) {  
519 - SrsMessage* msg = *it;  
520 - srs_freep(msg);  
521 - }  
522 - queue.clear();  
523 - }  
524 -public:  
525 - virtual bool empty()  
526 - {  
527 - return queue.empty();  
528 - }  
529 - virtual SrsMessage* pump()  
530 - {  
531 - SrsMessage* msg = *queue.begin();  
532 - queue.erase(queue.begin());  
533 - return msg;  
534 - }  
535 -public:  
536 - virtual int start()  
537 - {  
538 - return trd->start();  
539 - }  
540 - virtual void stop()  
541 - {  
542 - trd->stop();  
543 - }  
544 - virtual int cycle()  
545 - {  
546 - int ret = ERROR_SUCCESS;  
547 -  
548 - SrsMessage* msg = NULL;  
549 -  
550 - if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) {  
551 - if (!srs_is_client_gracefully_close(ret)) {  
552 - srs_error("recv client control message failed. ret=%d", ret);  
553 - }  
554 -  
555 - // we use no timeout to recv, should never got any error.  
556 - trd->stop_loop();  
557 -  
558 - return ret;  
559 - }  
560 - srs_verbose("play loop recv message. ret=%d", ret);  
561 -  
562 - return ret;  
563 - }  
564 -};  
565 -  
566 int SrsRtmpConn::playing(SrsSource* source) 497 int SrsRtmpConn::playing(SrsSource* source)
567 { 498 {
568 int ret = ERROR_SUCCESS; 499 int ret = ERROR_SUCCESS;
@@ -581,7 +512,7 @@ int SrsRtmpConn::playing(SrsSource* source) @@ -581,7 +512,7 @@ int SrsRtmpConn::playing(SrsSource* source)
581 512
582 // use isolate thread to recv, 513 // use isolate thread to recv,
583 // start isolate recv thread. 514 // start isolate recv thread.
584 - IsolateRecvThread trd(rtmp); 515 + SrsRecvThread trd(rtmp);
585 if ((ret = trd.start()) != ERROR_SUCCESS) { 516 if ((ret = trd.start()) != ERROR_SUCCESS) {
586 srs_error("start isolate recv thread failed. ret=%d", ret); 517 srs_error("start isolate recv thread failed. ret=%d", ret);
587 return ret; 518 return ret;
@@ -600,7 +531,7 @@ int SrsRtmpConn::playing(SrsSource* source) @@ -600,7 +531,7 @@ int SrsRtmpConn::playing(SrsSource* source)
600 return ret; 531 return ret;
601 } 532 }
602 533
603 -int SrsRtmpConn::do_playing(SrsSource* source, IsolateRecvThread* trd) 534 +int SrsRtmpConn::do_playing(SrsSource* source, SrsRecvThread* trd)
604 { 535 {
605 int ret = ERROR_SUCCESS; 536 int ret = ERROR_SUCCESS;
606 537
@@ -49,7 +49,7 @@ class SrsBandwidth; @@ -49,7 +49,7 @@ class SrsBandwidth;
49 class SrsKbps; 49 class SrsKbps;
50 class SrsRtmpClient; 50 class SrsRtmpClient;
51 class SrsSharedPtrMessage; 51 class SrsSharedPtrMessage;
52 -class IsolateRecvThread; 52 +class SrsRecvThread;
53 53
54 /** 54 /**
55 * the client provides the main logic control for RTMP clients. 55 * the client provides the main logic control for RTMP clients.
@@ -89,7 +89,7 @@ private: @@ -89,7 +89,7 @@ private:
89 virtual int stream_service_cycle(); 89 virtual int stream_service_cycle();
90 virtual int check_vhost(); 90 virtual int check_vhost();
91 virtual int playing(SrsSource* source); 91 virtual int playing(SrsSource* source);
92 - virtual int do_playing(SrsSource* source, IsolateRecvThread* trd); 92 + virtual int do_playing(SrsSource* source, SrsRecvThread* trd);
93 virtual int fmle_publishing(SrsSource* source); 93 virtual int fmle_publishing(SrsSource* source);
94 virtual int do_fmle_publishing(SrsSource* source); 94 virtual int do_fmle_publishing(SrsSource* source);
95 virtual int flash_publishing(SrsSource* source); 95 virtual int flash_publishing(SrsSource* source);
@@ -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 29 34 +#define VERSION_REVISION 30
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"
@@ -92,6 +92,8 @@ file @@ -92,6 +92,8 @@ file
92 ..\app\srs_app_kbps.cpp, 92 ..\app\srs_app_kbps.cpp,
93 ..\app\srs_app_log.hpp, 93 ..\app\srs_app_log.hpp,
94 ..\app\srs_app_log.cpp, 94 ..\app\srs_app_log.cpp,
  95 + ..\app\srs_app_recv_thread.hpp,
  96 + ..\app\srs_app_recv_thread.cpp,
95 ..\app\srs_app_refer.hpp, 97 ..\app\srs_app_refer.hpp,
96 ..\app\srs_app_refer.cpp, 98 ..\app\srs_app_refer.cpp,
97 ..\app\srs_app_reload.hpp, 99 ..\app\srs_app_reload.hpp,