Skip to content

Commit

Permalink
fix #244, conn thread use cond to wait for recv thread error. 2.0.47.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Dec 3, 2014
1 parent 565f29e commit 787ab67
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 39 deletions.
44 changes: 14 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ Supported operating systems and hardware:
* 2013-10-17, Created.<br/>

## History
* v2.0, 2014-12-03, fix [#244](https://github.com/winlinvip/simple-rtmp-server/issues/244), conn thread use cond to wait for recv thread error. 2.0.47.
* v2.0, 2014-12-02, merge [#239](https://github.com/winlinvip/simple-rtmp-server/pull/239), traverse the token before response connect. 2.0.45.
* v2.0, 2014-12-02, srs-librtmp support hijack io apis for st-load. 2.0.42.
* v2.0, 2014-12-01, for [#237](https://github.com/winlinvip/simple-rtmp-server/issues/237), refine syscall for recv, supports 1.5k clients. 2.0.41.
Expand Down Expand Up @@ -703,47 +704,30 @@ Supported operating systems and hardware:

## Performance

Performance benchmark history, on virtual box:
Performance benchmark history, on virtual box.

### Play benchmark

The play benchmark by st-load:

* 2013-11-28, SRS 0.5.0, 1.8k(1800)clients, 90%CPU, 41MB. [benchmark](https://github.com/winlinvip/simple-rtmp-server/commit/023e23bc8261bec15a70a7ae932098fb4f82b679)
* 2014-07-12, SRS 0.9.156, 1.8k(1800)clients, 68%CPU, 38MB. [benchmark](https://github.com/winlinvip/simple-rtmp-server/commit/e2d273f4939348374bf9644df9d54c4293b39c1a)
* 2014-07-12, SRS 0.9.156, 2.7k(2700)clients, 89%CPU, 61MB. [benchmark](https://github.com/winlinvip/simple-rtmp-server/commit/6d12280b7cc54c465b1caf8b1402149e77c4c7d9)
* 2014-11-11, SRS 1.0.5, 2.7k(2700)clients, 85%CPU, 66MB. (1.0 equals 2.0.12)
* 2014-11-11, SRS 1.0.5, 2.7k(2700)clients, 85%CPU, 66MB.
* 2014-11-11, SRS 2.0.12, 2.7k(2700)clients, 85%CPU, 66MB.
* 2014-11-12, SRS 2.0.14, 2.7k(2700)clients, 69%CPU, 59MB.
* 2014-11-12, SRS 2.0.14, 3.5k(3500)clients, 95%CPU, 78MB.
* 2014-11-13, SRS 2.0.15, 6.0k(6000)clients, 82%CPU, 203MB. (500 publishers).
* 2014-11-13, SRS 2.0.15, 6.0k(6000)clients, 82%CPU, 203MB.
* 2014-11-22, SRS 2.0.30, 7.5k(7500)clients, 87%CPU, 320MB.
* 2014-12-01, SRS 2.0.41, 7.5k(7500)clients, 87%CPU, 320MB. (1500 publishers).

Latest benchmark(2014-07-12):
* See also: [Performance for x86/x64 Test Guide](https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_Performance)
* See also: [Performance for RaspberryPi](https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_RaspberryPi)

1. 300 connections, 150Mbps, 500kbps, CPU 5.7%, MEM 9208KB.
1. 600 connections, 300Mbps, 500kbps, CPU 18.3%, MEM 13MB.
1. 900 connections, 450Mbps, 500kbps, CPU 27.9%, MEM 20MB.
1. 1200 connections, 600Mbps, 500kbps, CPU 43.9%, MEM 26MB.
1. 1500 connections, 750Mbps, 500kbps, CPU 55.2%, MEM 32MB.
1. 1800 connections, 900Mbps, 500kbps, CPU 68.8%, MEM 38MB.
1. 2100 connections, 1050Mbps, 500kbps, CPU 75.7%, MEM 46MB.
1. 2400 connections, 1200Mbps, 500kbps, CPU 83.7%, MEM 54MB.
1. 2700 connections, 1350Mbps, 500kbps, CPU 89.9%, MEM 61MB.
### Publish benchmark

<pre>
[winlin@dev6 srs]$ dstat
----total-cpu-usage---- -dsk/total- ---net/lo-- ---paging-- ---system--
usr sys idl wai hiq siq| read writ| recv send| in out | int csw
29 17 39 0 0 15| 0 5325B| 163M 163M| 0 0 |4331 3386
30 16 38 0 0 16| 0 5325B| 160M 160M| 0 0 |4252 3332
30 15 37 0 0 17| 0 7646B| 169M 169M| 0 0 |4015 2886
30 17 36 0 0 17| 0 1638B| 197M 197M| 0 0 |4021 3037
31 17 35 0 0 17| 0 410B| 204M 204M| 0 0 |4181 3243
33 17 32 0 0 18| 0 2185B| 191M 191M| 0 0 |4305 3592
31 15 36 0 0 18| 0 1229B| 127M 127M| 0 0 |4446 3822
34 18 30 0 0 18| 0 0 | 231M 231M| 0 0 |4461 3691
32 17 33 0 0 18| 0 410B| 169M 169M| 0 0 |4518 3788
</pre>
The publish benchmark by st-load:

* See also: [Performance for x86/x64 Test Guide](https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_Performance)
* See also: [Performance for RaspberryPi](https://github.com/winlinvip/simple-rtmp-server/wiki/v1_CN_RaspberryPi)
* 2014-12-03, SRS 1.0.10, 1k(1000) publishers, xx%CPU, xxMB.

## Architecture

Expand Down
22 changes: 22 additions & 0 deletions trunk/src/app/srs_app_recv_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,25 @@ SrsPublishRecvThread::SrsPublishRecvThread(

recv_error_code = ERROR_SUCCESS;
_nb_msgs = 0;
error = st_cond_new();
}

SrsPublishRecvThread::~SrsPublishRecvThread()
{
trd.stop();
st_cond_destroy(error);
}

int SrsPublishRecvThread::wait(int timeout_ms)
{
if (recv_error_code != ERROR_SUCCESS) {
return recv_error_code;
}

// ignore any return of cond wait.
st_cond_timedwait(error, timeout_ms * 1000);

return ERROR_SUCCESS;
}

int64_t SrsPublishRecvThread::nb_msgs()
Expand Down Expand Up @@ -282,6 +296,10 @@ int SrsPublishRecvThread::handle(SrsMessage* msg)
void SrsPublishRecvThread::on_recv_error(int ret)
{
recv_error_code = ret;

// when recv thread error, signal the conn thread to process it.
// @see https://github.com/winlinvip/simple-rtmp-server/issues/244
st_cond_signal(error);
}

void SrsPublishRecvThread::on_thread_start()
Expand All @@ -294,4 +312,8 @@ void SrsPublishRecvThread::on_thread_stop()
{
// we donot set the auto response to true,
// for we donot set to false yet.

// when thread stop, signal the conn thread which wait.
// @see https://github.com/winlinvip/simple-rtmp-server/issues/244
st_cond_signal(error);
}
8 changes: 8 additions & 0 deletions trunk/src/app/srs_app_recv_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,22 @@ class SrsPublishRecvThread : public ISrsMessageHandler
// the recv thread error code.
int recv_error_code;
SrsRtmpConn* _conn;
// the params for conn callback.
SrsSource* _source;
bool _is_fmle;
bool _is_edge;
// the error timeout cond
// @see https://github.com/winlinvip/simple-rtmp-server/issues/244
st_cond_t error;
public:
SrsPublishRecvThread(SrsRtmpServer* rtmp_sdk, int timeout_ms,
SrsRtmpConn* conn, SrsSource* source, bool is_fmle, bool is_edge);
virtual ~SrsPublishRecvThread();
public:
/**
* wait for error for some timeout.
*/
virtual int wait(int timeout_ms);
virtual int64_t nb_msgs();
virtual int error_code();
public:
Expand Down
16 changes: 7 additions & 9 deletions trunk/src/app/srs_app_rtmp_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,17 +750,15 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd)

int64_t nb_msgs = 0;
while (true) {
// use small loop to check the error code, interval = 30s/43 = 697ms.
for (int i = 0; i < 43; i++) {
st_usleep(SRS_CONSTS_RTMP_RECV_TIMEOUT_US / 43);
// cond wait for error.
trd->wait(SRS_CONSTS_RTMP_RECV_TIMEOUT_US / 1000);

// check the thread error code.
if ((ret = trd->error_code()) != ERROR_SUCCESS) {
if (!srs_is_client_gracefully_close(ret)) {
srs_error("recv thread failed. ret=%d", ret);
}
return ret;
// check the thread error code.
if ((ret = trd->error_code()) != ERROR_SUCCESS) {
if (!srs_is_client_gracefully_close(ret)) {
srs_error("recv thread failed. ret=%d", ret);
}
return ret;
}

// when not got any messages, timeout.
Expand Down

0 comments on commit 787ab67

Please sign in to comment.