Skip to content

Commit

Permalink
fix #217, remove timeout recv, support 7.5k+ 250kbps clients. 2.0.30.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Nov 22, 2014
1 parent 622218c commit 58136ec
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 77 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,12 @@ Supported operating systems and hardware:
[CN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_SrsLibrtmp#publish-h264-raw-data),
[EN](https://github.com/winlinvip/simple-rtmp-server/wiki/v2_EN_SrsLibrtmp#publish-h264-raw-data)
) by srs-librtmp.
1. Support [6k+ clients](https://github.com/winlinvip/simple-rtmp-server/issues/194), 4Gbps per process.
1. Support [6k+ clients](https://github.com/winlinvip/simple-rtmp-server/issues/194), 3Gbps per process.
1. Suppport [English wiki](https://github.com/winlinvip/simple-rtmp-server/wiki/v1_EN_Home).
1. Research and simplify st, [bug #182](https://github.com/winlinvip/simple-rtmp-server/issues/182).
1. Support compile [srs-librtmp on windows](https://github.com/winlinvip/srs.librtmp),
[bug #213](https://github.com/winlinvip/simple-rtmp-server/issues/213).
1. Support [7.5k+ clients](https://github.com/winlinvip/simple-rtmp-server/issues/217), 4Gbps per process.
1. [no-plan] Support <500ms latency, FRSC(Fast RTMP-compatible Stream Channel tech).
1. [no-plan] Support RTMP 302 redirect [#92](https://github.com/winlinvip/simple-rtmp-server/issues/92).
1. [no-plan] Support multiple processes, for both origin and edge
Expand Down Expand Up @@ -482,6 +483,7 @@ Supported operating systems and hardware:
* 2013-10-17, Created.<br/>

## History
* 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.
* v2.0, 2014-11-21, srs-librtmp add rtmp prefix for rtmp/utils/human apis. 2.0.29.
* v2.0, 2014-11-21, refine examples of srs-librtmp, add srs_print_rtmp_packet. 2.0.28.
* v2.0, 2014-11-20, fix [#212](https://github.com/winlinvip/simple-rtmp-server/issues/212), support publish audio raw frames. 2.0.27
Expand Down Expand Up @@ -700,6 +702,7 @@ Performance benchmark history, on virtual box:
* 2014-11-12, SRS 2.0.14, 2700clients, 69%CPU, 59MB.
* 2014-11-12, SRS 2.0.14, 3500clients, 95%CPU, 78MB.
* 2014-11-13, SRS 2.0.15, 6000clients, 82%CPU, 203MB. (500 publishers).
* 2014-11-22, SRS 2.0.30, 7500clients, 87%CPU, 320MB.

Latest benchmark(2014-07-12):

Expand Down
3 changes: 2 additions & 1 deletion trunk/configure
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
"srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config"
"srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks"
"srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge"
"srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_avc_aac")
"srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_avc_aac"
"srs_app_recv_thread")
APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
APP_OBJS="${MODULE_OBJS[@]}"
fi
Expand Down
98 changes: 98 additions & 0 deletions trunk/src/app/srs_app_recv_thread.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
The MIT License (MIT)
Copyright (c) 2013-2014 winlin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <srs_app_recv_thread.hpp>

#include <srs_protocol_rtmp.hpp>
#include <srs_protocol_stack.hpp>

SrsRecvThread::SrsRecvThread(SrsRtmpServer* rtmp_sdk)
{
rtmp = rtmp_sdk;
trd = new SrsThread(this, 0, true);
}

SrsRecvThread::~SrsRecvThread()
{
// stop recv thread.
stop();

// destroy the thread.
srs_freep(trd);

// clear all messages.
std::vector<SrsMessage*>::iterator it;
for (it = queue.begin(); it != queue.end(); ++it) {
SrsMessage* msg = *it;
srs_freep(msg);
}
queue.clear();
}

bool SrsRecvThread::empty()
{
return queue.empty();
}

SrsMessage* SrsRecvThread::pump()
{
srs_assert(!queue.empty());

SrsMessage* msg = *queue.begin();

queue.erase(queue.begin());

return msg;
}

int SrsRecvThread::start()
{
return trd->start();
}

void SrsRecvThread::stop()
{
trd->stop();
}

int SrsRecvThread::cycle()
{
int ret = ERROR_SUCCESS;

SrsMessage* msg = NULL;

if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) {
if (!srs_is_client_gracefully_close(ret)) {
srs_error("recv client control message failed. ret=%d", ret);
}

// we use no timeout to recv, should never got any error.
trd->stop_loop();

return ret;
}
srs_verbose("play loop recv message. ret=%d", ret);

return ret;
}

65 changes: 65 additions & 0 deletions trunk/src/app/srs_app_recv_thread.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
The MIT License (MIT)
Copyright (c) 2013-2014 winlin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef SRS_APP_RECV_THREAD_HPP
#define SRS_APP_RECV_THREAD_HPP

/*
#include <srs_app_recv_thread.hpp>
*/

#include <srs_core.hpp>

#include <vector>

#include <srs_app_thread.hpp>

class SrsRtmpServer;
class SrsMessage;

/**
* the recv thread used to replace the timeout recv,
* which hurt performance for the epoll_ctrl is frequently used.
* @see: SrsRtmpConn::playing
* @see: https://github.com/winlinvip/simple-rtmp-server/issues/217
*/
class SrsRecvThread : public ISrsThreadHandler
{
private:
SrsThread* trd;
SrsRtmpServer* rtmp;
std::vector<SrsMessage*> queue;
public:
SrsRecvThread(SrsRtmpServer* rtmp_sdk);
virtual ~SrsRecvThread();
public:
virtual bool empty();
virtual SrsMessage* pump();
public:
virtual int start();
virtual void stop();
virtual int cycle();
};

#endif

75 changes: 3 additions & 72 deletions trunk/src/app/srs_app_rtmp_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ using namespace std;
#include <srs_app_utility.hpp>
#include <srs_protocol_msg_array.hpp>
#include <srs_protocol_amf0.hpp>
#include <srs_app_recv_thread.hpp>

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

class IsolateRecvThread : public ISrsThreadHandler
{
private:
SrsThread* trd;
SrsRtmpServer* rtmp;
std::vector<SrsMessage*> queue;
public:
IsolateRecvThread(SrsRtmpServer* rtmp_sdk)
{
rtmp = rtmp_sdk;
trd = new SrsThread(this, 0, true);
}
virtual ~IsolateRecvThread()
{
// stop recv thread.
stop();

// destroy the thread.
srs_freep(trd);

// clear all messages.
std::vector<SrsMessage*>::iterator it;
for (it = queue.begin(); it != queue.end(); ++it) {
SrsMessage* msg = *it;
srs_freep(msg);
}
queue.clear();
}
public:
virtual bool empty()
{
return queue.empty();
}
virtual SrsMessage* pump()
{
SrsMessage* msg = *queue.begin();
queue.erase(queue.begin());
return msg;
}
public:
virtual int start()
{
return trd->start();
}
virtual void stop()
{
trd->stop();
}
virtual int cycle()
{
int ret = ERROR_SUCCESS;

SrsMessage* msg = NULL;

if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) {
if (!srs_is_client_gracefully_close(ret)) {
srs_error("recv client control message failed. ret=%d", ret);
}

// we use no timeout to recv, should never got any error.
trd->stop_loop();

return ret;
}
srs_verbose("play loop recv message. ret=%d", ret);

return ret;
}
};

int SrsRtmpConn::playing(SrsSource* source)
{
int ret = ERROR_SUCCESS;
Expand All @@ -581,7 +512,7 @@ int SrsRtmpConn::playing(SrsSource* source)

// use isolate thread to recv,
// start isolate recv thread.
IsolateRecvThread trd(rtmp);
SrsRecvThread trd(rtmp);
if ((ret = trd.start()) != ERROR_SUCCESS) {
srs_error("start isolate recv thread failed. ret=%d", ret);
return ret;
Expand All @@ -600,7 +531,7 @@ int SrsRtmpConn::playing(SrsSource* source)
return ret;
}

int SrsRtmpConn::do_playing(SrsSource* source, IsolateRecvThread* trd)
int SrsRtmpConn::do_playing(SrsSource* source, SrsRecvThread* trd)
{
int ret = ERROR_SUCCESS;

Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_rtmp_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SrsBandwidth;
class SrsKbps;
class SrsRtmpClient;
class SrsSharedPtrMessage;
class IsolateRecvThread;
class SrsRecvThread;

/**
* the client provides the main logic control for RTMP clients.
Expand Down Expand Up @@ -89,7 +89,7 @@ class SrsRtmpConn : public virtual SrsConnection, public virtual ISrsReloadHandl
virtual int stream_service_cycle();
virtual int check_vhost();
virtual int playing(SrsSource* source);
virtual int do_playing(SrsSource* source, IsolateRecvThread* trd);
virtual int do_playing(SrsSource* source, SrsRecvThread* trd);
virtual int fmle_publishing(SrsSource* source);
virtual int do_fmle_publishing(SrsSource* source);
virtual int flash_publishing(SrsSource* source);
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 29
#define VERSION_REVISION 30
// server info.
#define RTMP_SIG_SRS_KEY "SRS"
#define RTMP_SIG_SRS_ROLE "origin/edge server"
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/srs/srs.upp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ file
..\app\srs_app_kbps.cpp,
..\app\srs_app_log.hpp,
..\app\srs_app_log.cpp,
..\app\srs_app_recv_thread.hpp,
..\app\srs_app_recv_thread.cpp,
..\app\srs_app_refer.hpp,
..\app\srs_app_refer.cpp,
..\app\srs_app_reload.hpp,
Expand Down

0 comments on commit 58136ec

Please sign in to comment.