diff --git a/trunk/src/app/srs_app_recv_thread.cpp b/trunk/src/app/srs_app_recv_thread.cpp index b9dc9818e..74de0016b 100644 --- a/trunk/src/app/srs_app_recv_thread.cpp +++ b/trunk/src/app/srs_app_recv_thread.cpp @@ -295,7 +295,7 @@ void SrsPublishRecvThread::on_thread_start() // enable the merge read // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 - rtmp->set_merge_read(true, nb_rbuf, this); + rtmp->set_merge_read(true, this); #endif } @@ -311,7 +311,7 @@ void SrsPublishRecvThread::on_thread_stop() #ifdef SRS_PERF_MERGED_READ // disable the merge read // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 - rtmp->set_merge_read(false, 0, NULL); + rtmp->set_merge_read(false, NULL); #endif } diff --git a/trunk/src/core/srs_core_performance.hpp b/trunk/src/core/srs_core_performance.hpp index 0b4853978..bc82fd109 100644 --- a/trunk/src/core/srs_core_performance.hpp +++ b/trunk/src/core/srs_core_performance.hpp @@ -39,40 +39,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * when it on and read small bytes, we sleep to wait more data., * that is, we merge some data to read together. * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 -* @remark other macros: -* SOCKET_MAX_BUF, the max size of user-space buffer. -* SOCKET_READ_SIZE, the user space buffer for socket. -* SRS_MR_MAX_BITRATE_KBPS, the kbps of stream for system to guess the sleep time. -* SRS_MR_AVERAGE_BITRATE_KBPS, the average kbps of system. -* SRS_MR_MIN_BITRATE_KBPS, the min kbps of system. -* SRS_MR_MAX_SLEEP_MS, the max sleep time, the latency+ when sleep+. -* SRS_MR_SMALL_BYTES, sleep when got small bytes, the latency+ when small+. -* SRS_MR_SMALL_PERCENT, to calc the small bytes = SRS_MR_SOCKET_BUFFER/percent. -* SRS_MR_SOCKET_BUFFER, the socket buffer to set fd. -* @remark the actual socket buffer used to set the buffer user-space size. -* buffer = min(SOCKET_MAX_BUF, SRS_MR_SOCKET_BUFFER, SOCKET_READ_SIZE) -* small bytes = max(buffer/SRS_MR_SMALL_PERCENT, SRS_MR_SMALL_BYTES) -* sleep = calc the sleep by kbps and buffer. -* @remark the main merged-read algorithm: -* while true: -* nread = read from socket. -* sleep if nread < small bytes -* process bytes. * @example, for the default settings, this algorithm will use: -* socket buffer set to 64KB, -* user space buffer set to 64KB, -* buffer=65536B, small=4096B, sleep=780ms * that is, when got nread bytes smaller than 4KB, sleep(780ms). */ #if 1 // to enable merged read. #define SRS_PERF_MERGED_READ // the max sleep time in ms - #define SRS_MR_MAX_SLEEP_MS 1000 + #define SRS_MR_MAX_SLEEP_MS 780 // the max small bytes to group #define SRS_MR_SMALL_BYTES 4096 // the underlayer api will set to SRS_MR_SOCKET_BUFFER bytes. - // 4KB=4096, 8KB=8192, 16KB=16384, 32KB=32768, 64KB=65536 + // 4KB=4096, 8KB=8192, 16KB=16384, 32KB=32768, 64KB=65536, + // 128KB=131072, 256KB=262144, 512KB=524288 + // the buffer should set to SRS_MR_MAX_SLEEP_MS*kbps/8, + // for example, your system delivery stream in 1000kbps, + // sleep 800ms for small bytes, the buffer should set to: + // 800*1000/8=100000B(about 128KB). #define SRS_MR_SOCKET_BUFFER 65536 #endif diff --git a/trunk/src/rtmp/srs_protocol_buffer.cpp b/trunk/src/rtmp/srs_protocol_buffer.cpp index d222e62c9..c2ab1ce29 100644 --- a/trunk/src/rtmp/srs_protocol_buffer.cpp +++ b/trunk/src/rtmp/srs_protocol_buffer.cpp @@ -186,17 +186,10 @@ int SrsFastBuffer::grow(ISrsBufferReader* reader, int required_size) } #ifdef SRS_PERF_MERGED_READ -void SrsFastBuffer::set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler) +void SrsFastBuffer::set_merge_read(bool v, IMergeReadHandler* handler) { merged_read = v; _handler = handler; - - // limit the max buffer. - int buffer_size = srs_min(max_buffer, SRS_MR_SOCKET_BUFFER); - - if (v && buffer_size != nb_buffer) { - reset_buffer(buffer_size); - } } #endif diff --git a/trunk/src/rtmp/srs_protocol_buffer.hpp b/trunk/src/rtmp/srs_protocol_buffer.hpp index bb9f69cc1..061b06721 100644 --- a/trunk/src/rtmp/srs_protocol_buffer.hpp +++ b/trunk/src/rtmp/srs_protocol_buffer.hpp @@ -157,11 +157,10 @@ public: * when it on and read small bytes, we sleep to wait more data., * that is, we merge some data to read together. * @param v true to ename merged read. - * @param max_buffer the max buffer size, the socket buffer. * @param handler the handler when merge read is enabled. * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 */ - virtual void set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler); + virtual void set_merge_read(bool v, IMergeReadHandler* handler); #endif private: virtual void reset_buffer(int size); diff --git a/trunk/src/rtmp/srs_protocol_rtmp.cpp b/trunk/src/rtmp/srs_protocol_rtmp.cpp index 2c098a6d2..7c14bac49 100644 --- a/trunk/src/rtmp/srs_protocol_rtmp.cpp +++ b/trunk/src/rtmp/srs_protocol_rtmp.cpp @@ -746,9 +746,9 @@ void SrsRtmpServer::set_auto_response(bool v) } #ifdef SRS_PERF_MERGED_READ -void SrsRtmpServer::set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler) +void SrsRtmpServer::set_merge_read(bool v, IMergeReadHandler* handler) { - protocol->set_merge_read(v, max_buffer, handler); + protocol->set_merge_read(v, handler); } #endif diff --git a/trunk/src/rtmp/srs_protocol_rtmp.hpp b/trunk/src/rtmp/srs_protocol_rtmp.hpp index cab5b3065..9b5a355ca 100644 --- a/trunk/src/rtmp/srs_protocol_rtmp.hpp +++ b/trunk/src/rtmp/srs_protocol_rtmp.hpp @@ -350,11 +350,10 @@ public: * when it on and read small bytes, we sleep to wait more data., * that is, we merge some data to read together. * @param v true to ename merged read. - * @param max_buffer the max buffer size, the socket buffer. * @param handler the handler when merge read is enabled. * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 */ - virtual void set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler); + virtual void set_merge_read(bool v, IMergeReadHandler* handler); #endif /** * set/get the recv timeout in us. diff --git a/trunk/src/rtmp/srs_protocol_stack.cpp b/trunk/src/rtmp/srs_protocol_stack.cpp index 10ece0e0d..a154d8131 100644 --- a/trunk/src/rtmp/srs_protocol_stack.cpp +++ b/trunk/src/rtmp/srs_protocol_stack.cpp @@ -497,9 +497,9 @@ int SrsProtocol::manual_response_flush() } #ifdef SRS_PERF_MERGED_READ -void SrsProtocol::set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler) +void SrsProtocol::set_merge_read(bool v, IMergeReadHandler* handler) { - in_buffer->set_merge_read(v, max_buffer, handler); + in_buffer->set_merge_read(v, handler); } #endif diff --git a/trunk/src/rtmp/srs_protocol_stack.hpp b/trunk/src/rtmp/srs_protocol_stack.hpp index 026c755dc..9c909c87b 100644 --- a/trunk/src/rtmp/srs_protocol_stack.hpp +++ b/trunk/src/rtmp/srs_protocol_stack.hpp @@ -284,11 +284,10 @@ public: * when it on and read small bytes, we sleep to wait more data., * that is, we merge some data to read together. * @param v true to ename merged read. - * @param max_buffer the max buffer size, the socket buffer. * @param handler the handler when merge read is enabled. * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 */ - virtual void set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler); + virtual void set_merge_read(bool v, IMergeReadHandler* handler); #endif public: /**