winlin

refine code for bug #217, use recv thread to set the timeout.

... ... @@ -96,3 +96,27 @@ int SrsRecvThread::cycle()
return ret;
}
void SrsRecvThread::on_thread_start()
{
// the multiple messages writev improve performance large,
// but the timeout recv will cause 33% sys call performance,
// to use isolate thread to recv, can improve about 33% performance.
// @see https://github.com/winlinvip/simple-rtmp-server/issues/194
// @see: https://github.com/winlinvip/simple-rtmp-server/issues/217
rtmp->set_recv_timeout(ST_UTIME_NO_TIMEOUT);
// disable the protocol auto response,
// for the isolate recv thread should never send any messages.
rtmp->set_auto_response(false);
}
void SrsRecvThread::on_thread_stop()
{
// enable the protocol auto response,
// for the isolate recv thread terminated.
rtmp->set_auto_response(true);
// reset the timeout to pulse mode.
rtmp->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
}
... ...
... ... @@ -59,6 +59,9 @@ public:
virtual int start();
virtual void stop();
virtual int cycle();
public:
virtual void on_thread_start();
virtual void on_thread_stop();
};
#endif
... ...
... ... @@ -498,21 +498,11 @@ int SrsRtmpConn::playing(SrsSource* source)
{
int ret = ERROR_SUCCESS;
// the multiple messages writev improve performance large,
// but the timeout recv will cause 33% sys call performance,
// to use isolate thread to recv, can improve about 33% performance.
// @see https://github.com/winlinvip/simple-rtmp-server/issues/194
// use isolate thread to recv,
// @see: https://github.com/winlinvip/simple-rtmp-server/issues/217
//rtmp->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
rtmp->set_recv_timeout(ST_UTIME_NO_TIMEOUT);
// disable the protocol auto response,
// for the isolate recv thread should never send any messages.
rtmp->set_auto_response(false);
SrsRecvThread trd(rtmp);
// use isolate thread to recv,
// start isolate recv thread.
SrsRecvThread trd(rtmp);
if ((ret = trd.start()) != ERROR_SUCCESS) {
srs_error("start isolate recv thread failed. ret=%d", ret);
return ret;
... ... @@ -524,10 +514,6 @@ int SrsRtmpConn::playing(SrsSource* source)
// stop isolate recv thread
trd.stop();
// enable the protocol auto response,
// for the isolate recv thread terminated.
rtmp->set_auto_response(true);
return ret;
}
... ...