Skip to content

Commit 58136ec

Browse files
committed
fix #217, remove timeout recv, support 7.5k+ 250kbps clients. 2.0.30.
1 parent 622218c commit 58136ec

File tree

8 files changed

+177
-77
lines changed

8 files changed

+177
-77
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,12 @@ Supported operating systems and hardware:
445445
[CN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_SrsLibrtmp#publish-h264-raw-data),
446446
[EN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_EN_SrsLibrtmp#publish-h264-raw-data)
447447
) 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.
449449
1. Suppport [English wiki](https://github.com/winlinvip/simple-rtmp-server/wiki/v1_EN_Home).
450450
1. Research and simplify st, [bug #182](https://github.com/winlinvip/simple-rtmp-server/issues/182).
451451
1. Support compile [srs-librtmp on windows](https://github.com/winlinvip/srs.librtmp),
452452
[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.
453454
1. [no-plan] Support <500ms latency, FRSC(Fast RTMP-compatible Stream Channel tech).
454455
1. [no-plan] Support RTMP 302 redirect [#92](https://github.com/winlinvip/simple-rtmp-server/issues/92).
455456
1. [no-plan] Support multiple processes, for both origin and edge
@@ -482,6 +483,7 @@ Supported operating systems and hardware:
482483
* 2013-10-17, Created.<br/>
483484

484485
## 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.
485487
* v2.0, 2014-11-21, srs-librtmp add rtmp prefix for rtmp/utils/human apis. 2.0.29.
486488
* v2.0, 2014-11-21, refine examples of srs-librtmp, add srs_print_rtmp_packet. 2.0.28.
487489
* 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:
700702
* 2014-11-12, SRS 2.0.14, 2700clients, 69%CPU, 59MB.
701703
* 2014-11-12, SRS 2.0.14, 3500clients, 95%CPU, 78MB.
702704
* 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.
703706

704707
Latest benchmark(2014-07-12):
705708

trunk/configure

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
388388
"srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config"
389389
"srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks"
390390
"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")
392393
APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
393394
APP_OBJS="${MODULE_OBJS[@]}"
394395
fi

trunk/src/app/srs_app_recv_thread.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,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+
#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+

trunk/src/app/srs_app_recv_thread.hpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+

trunk/src/app/srs_app_rtmp_conn.cpp

Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ using namespace std;
4848
#include <srs_app_utility.hpp>
4949
#include <srs_protocol_msg_array.hpp>
5050
#include <srs_protocol_amf0.hpp>
51+
#include <srs_app_recv_thread.hpp>
5152

5253
// when stream is busy, for example, streaming is already
5354
// publishing, when a new client to request to publish,
@@ -493,76 +494,6 @@ int SrsRtmpConn::check_vhost()
493494
return ret;
494495
}
495496

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-
566497
int SrsRtmpConn::playing(SrsSource* source)
567498
{
568499
int ret = ERROR_SUCCESS;
@@ -581,7 +512,7 @@ int SrsRtmpConn::playing(SrsSource* source)
581512

582513
// use isolate thread to recv,
583514
// start isolate recv thread.
584-
IsolateRecvThread trd(rtmp);
515+
SrsRecvThread trd(rtmp);
585516
if ((ret = trd.start()) != ERROR_SUCCESS) {
586517
srs_error("start isolate recv thread failed. ret=%d", ret);
587518
return ret;
@@ -600,7 +531,7 @@ int SrsRtmpConn::playing(SrsSource* source)
600531
return ret;
601532
}
602533

603-
int SrsRtmpConn::do_playing(SrsSource* source, IsolateRecvThread* trd)
534+
int SrsRtmpConn::do_playing(SrsSource* source, SrsRecvThread* trd)
604535
{
605536
int ret = ERROR_SUCCESS;
606537

trunk/src/app/srs_app_rtmp_conn.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class SrsBandwidth;
4949
class SrsKbps;
5050
class SrsRtmpClient;
5151
class SrsSharedPtrMessage;
52-
class IsolateRecvThread;
52+
class SrsRecvThread;
5353

5454
/**
5555
* the client provides the main logic control for RTMP clients.
@@ -89,7 +89,7 @@ class SrsRtmpConn : public virtual SrsConnection, public virtual ISrsReloadHandl
8989
virtual int stream_service_cycle();
9090
virtual int check_vhost();
9191
virtual int playing(SrsSource* source);
92-
virtual int do_playing(SrsSource* source, IsolateRecvThread* trd);
92+
virtual int do_playing(SrsSource* source, SrsRecvThread* trd);
9393
virtual int fmle_publishing(SrsSource* source);
9494
virtual int do_fmle_publishing(SrsSource* source);
9595
virtual int flash_publishing(SrsSource* source);

trunk/src/core/srs_core.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3131
// current release version
3232
#define VERSION_MAJOR 2
3333
#define VERSION_MINOR 0
34-
#define VERSION_REVISION 29
34+
#define VERSION_REVISION 30
3535
// server info.
3636
#define RTMP_SIG_SRS_KEY "SRS"
3737
#define RTMP_SIG_SRS_ROLE "origin/edge server"

trunk/src/srs/srs.upp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ file
9292
..\app\srs_app_kbps.cpp,
9393
..\app\srs_app_log.hpp,
9494
..\app\srs_app_log.cpp,
95+
..\app\srs_app_recv_thread.hpp,
96+
..\app\srs_app_recv_thread.cpp,
9597
..\app\srs_app_refer.hpp,
9698
..\app\srs_app_refer.cpp,
9799
..\app\srs_app_reload.hpp,

0 commit comments

Comments
 (0)