正在显示
8 个修改的文件
包含
17 行增加
和
44 行删除
| @@ -295,7 +295,7 @@ void SrsPublishRecvThread::on_thread_start() | @@ -295,7 +295,7 @@ void SrsPublishRecvThread::on_thread_start() | ||
| 295 | 295 | ||
| 296 | // enable the merge read | 296 | // enable the merge read |
| 297 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 297 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 298 | - rtmp->set_merge_read(true, nb_rbuf, this); | 298 | + rtmp->set_merge_read(true, this); |
| 299 | #endif | 299 | #endif |
| 300 | } | 300 | } |
| 301 | 301 | ||
| @@ -311,7 +311,7 @@ void SrsPublishRecvThread::on_thread_stop() | @@ -311,7 +311,7 @@ void SrsPublishRecvThread::on_thread_stop() | ||
| 311 | #ifdef SRS_PERF_MERGED_READ | 311 | #ifdef SRS_PERF_MERGED_READ |
| 312 | // disable the merge read | 312 | // disable the merge read |
| 313 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 313 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 314 | - rtmp->set_merge_read(false, 0, NULL); | 314 | + rtmp->set_merge_read(false, NULL); |
| 315 | #endif | 315 | #endif |
| 316 | } | 316 | } |
| 317 | 317 |
| @@ -39,40 +39,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -39,40 +39,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 39 | * when it on and read small bytes, we sleep to wait more data., | 39 | * when it on and read small bytes, we sleep to wait more data., |
| 40 | * that is, we merge some data to read together. | 40 | * that is, we merge some data to read together. |
| 41 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 41 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 42 | -* @remark other macros: | ||
| 43 | -* SOCKET_MAX_BUF, the max size of user-space buffer. | ||
| 44 | -* SOCKET_READ_SIZE, the user space buffer for socket. | ||
| 45 | -* SRS_MR_MAX_BITRATE_KBPS, the kbps of stream for system to guess the sleep time. | ||
| 46 | -* SRS_MR_AVERAGE_BITRATE_KBPS, the average kbps of system. | ||
| 47 | -* SRS_MR_MIN_BITRATE_KBPS, the min kbps of system. | ||
| 48 | -* SRS_MR_MAX_SLEEP_MS, the max sleep time, the latency+ when sleep+. | ||
| 49 | -* SRS_MR_SMALL_BYTES, sleep when got small bytes, the latency+ when small+. | ||
| 50 | -* SRS_MR_SMALL_PERCENT, to calc the small bytes = SRS_MR_SOCKET_BUFFER/percent. | ||
| 51 | -* SRS_MR_SOCKET_BUFFER, the socket buffer to set fd. | ||
| 52 | -* @remark the actual socket buffer used to set the buffer user-space size. | ||
| 53 | -* buffer = min(SOCKET_MAX_BUF, SRS_MR_SOCKET_BUFFER, SOCKET_READ_SIZE) | ||
| 54 | -* small bytes = max(buffer/SRS_MR_SMALL_PERCENT, SRS_MR_SMALL_BYTES) | ||
| 55 | -* sleep = calc the sleep by kbps and buffer. | ||
| 56 | -* @remark the main merged-read algorithm: | ||
| 57 | -* while true: | ||
| 58 | -* nread = read from socket. | ||
| 59 | -* sleep if nread < small bytes | ||
| 60 | -* process bytes. | ||
| 61 | * @example, for the default settings, this algorithm will use: | 42 | * @example, for the default settings, this algorithm will use: |
| 62 | -* socket buffer set to 64KB, | ||
| 63 | -* user space buffer set to 64KB, | ||
| 64 | -* buffer=65536B, small=4096B, sleep=780ms | ||
| 65 | * that is, when got nread bytes smaller than 4KB, sleep(780ms). | 43 | * that is, when got nread bytes smaller than 4KB, sleep(780ms). |
| 66 | */ | 44 | */ |
| 67 | #if 1 | 45 | #if 1 |
| 68 | // to enable merged read. | 46 | // to enable merged read. |
| 69 | #define SRS_PERF_MERGED_READ | 47 | #define SRS_PERF_MERGED_READ |
| 70 | // the max sleep time in ms | 48 | // the max sleep time in ms |
| 71 | - #define SRS_MR_MAX_SLEEP_MS 1000 | 49 | + #define SRS_MR_MAX_SLEEP_MS 780 |
| 72 | // the max small bytes to group | 50 | // the max small bytes to group |
| 73 | #define SRS_MR_SMALL_BYTES 4096 | 51 | #define SRS_MR_SMALL_BYTES 4096 |
| 74 | // the underlayer api will set to SRS_MR_SOCKET_BUFFER bytes. | 52 | // the underlayer api will set to SRS_MR_SOCKET_BUFFER bytes. |
| 75 | - // 4KB=4096, 8KB=8192, 16KB=16384, 32KB=32768, 64KB=65536 | 53 | + // 4KB=4096, 8KB=8192, 16KB=16384, 32KB=32768, 64KB=65536, |
| 54 | + // 128KB=131072, 256KB=262144, 512KB=524288 | ||
| 55 | + // the buffer should set to SRS_MR_MAX_SLEEP_MS*kbps/8, | ||
| 56 | + // for example, your system delivery stream in 1000kbps, | ||
| 57 | + // sleep 800ms for small bytes, the buffer should set to: | ||
| 58 | + // 800*1000/8=100000B(about 128KB). | ||
| 76 | #define SRS_MR_SOCKET_BUFFER 65536 | 59 | #define SRS_MR_SOCKET_BUFFER 65536 |
| 77 | #endif | 60 | #endif |
| 78 | 61 |
| @@ -186,17 +186,10 @@ int SrsFastBuffer::grow(ISrsBufferReader* reader, int required_size) | @@ -186,17 +186,10 @@ int SrsFastBuffer::grow(ISrsBufferReader* reader, int required_size) | ||
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | #ifdef SRS_PERF_MERGED_READ | 188 | #ifdef SRS_PERF_MERGED_READ |
| 189 | -void SrsFastBuffer::set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler) | 189 | +void SrsFastBuffer::set_merge_read(bool v, IMergeReadHandler* handler) |
| 190 | { | 190 | { |
| 191 | merged_read = v; | 191 | merged_read = v; |
| 192 | _handler = handler; | 192 | _handler = handler; |
| 193 | - | ||
| 194 | - // limit the max buffer. | ||
| 195 | - int buffer_size = srs_min(max_buffer, SRS_MR_SOCKET_BUFFER); | ||
| 196 | - | ||
| 197 | - if (v && buffer_size != nb_buffer) { | ||
| 198 | - reset_buffer(buffer_size); | ||
| 199 | - } | ||
| 200 | } | 193 | } |
| 201 | #endif | 194 | #endif |
| 202 | 195 |
| @@ -157,11 +157,10 @@ public: | @@ -157,11 +157,10 @@ public: | ||
| 157 | * when it on and read small bytes, we sleep to wait more data., | 157 | * when it on and read small bytes, we sleep to wait more data., |
| 158 | * that is, we merge some data to read together. | 158 | * that is, we merge some data to read together. |
| 159 | * @param v true to ename merged read. | 159 | * @param v true to ename merged read. |
| 160 | - * @param max_buffer the max buffer size, the socket buffer. | ||
| 161 | * @param handler the handler when merge read is enabled. | 160 | * @param handler the handler when merge read is enabled. |
| 162 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 161 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 163 | */ | 162 | */ |
| 164 | - virtual void set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler); | 163 | + virtual void set_merge_read(bool v, IMergeReadHandler* handler); |
| 165 | #endif | 164 | #endif |
| 166 | private: | 165 | private: |
| 167 | virtual void reset_buffer(int size); | 166 | virtual void reset_buffer(int size); |
| @@ -746,9 +746,9 @@ void SrsRtmpServer::set_auto_response(bool v) | @@ -746,9 +746,9 @@ void SrsRtmpServer::set_auto_response(bool v) | ||
| 746 | } | 746 | } |
| 747 | 747 | ||
| 748 | #ifdef SRS_PERF_MERGED_READ | 748 | #ifdef SRS_PERF_MERGED_READ |
| 749 | -void SrsRtmpServer::set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler) | 749 | +void SrsRtmpServer::set_merge_read(bool v, IMergeReadHandler* handler) |
| 750 | { | 750 | { |
| 751 | - protocol->set_merge_read(v, max_buffer, handler); | 751 | + protocol->set_merge_read(v, handler); |
| 752 | } | 752 | } |
| 753 | #endif | 753 | #endif |
| 754 | 754 |
| @@ -350,11 +350,10 @@ public: | @@ -350,11 +350,10 @@ public: | ||
| 350 | * when it on and read small bytes, we sleep to wait more data., | 350 | * when it on and read small bytes, we sleep to wait more data., |
| 351 | * that is, we merge some data to read together. | 351 | * that is, we merge some data to read together. |
| 352 | * @param v true to ename merged read. | 352 | * @param v true to ename merged read. |
| 353 | - * @param max_buffer the max buffer size, the socket buffer. | ||
| 354 | * @param handler the handler when merge read is enabled. | 353 | * @param handler the handler when merge read is enabled. |
| 355 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 354 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 356 | */ | 355 | */ |
| 357 | - virtual void set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler); | 356 | + virtual void set_merge_read(bool v, IMergeReadHandler* handler); |
| 358 | #endif | 357 | #endif |
| 359 | /** | 358 | /** |
| 360 | * set/get the recv timeout in us. | 359 | * set/get the recv timeout in us. |
| @@ -497,9 +497,9 @@ int SrsProtocol::manual_response_flush() | @@ -497,9 +497,9 @@ int SrsProtocol::manual_response_flush() | ||
| 497 | } | 497 | } |
| 498 | 498 | ||
| 499 | #ifdef SRS_PERF_MERGED_READ | 499 | #ifdef SRS_PERF_MERGED_READ |
| 500 | -void SrsProtocol::set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler) | 500 | +void SrsProtocol::set_merge_read(bool v, IMergeReadHandler* handler) |
| 501 | { | 501 | { |
| 502 | - in_buffer->set_merge_read(v, max_buffer, handler); | 502 | + in_buffer->set_merge_read(v, handler); |
| 503 | } | 503 | } |
| 504 | #endif | 504 | #endif |
| 505 | 505 |
| @@ -284,11 +284,10 @@ public: | @@ -284,11 +284,10 @@ public: | ||
| 284 | * when it on and read small bytes, we sleep to wait more data., | 284 | * when it on and read small bytes, we sleep to wait more data., |
| 285 | * that is, we merge some data to read together. | 285 | * that is, we merge some data to read together. |
| 286 | * @param v true to ename merged read. | 286 | * @param v true to ename merged read. |
| 287 | - * @param max_buffer the max buffer size, the socket buffer. | ||
| 288 | * @param handler the handler when merge read is enabled. | 287 | * @param handler the handler when merge read is enabled. |
| 289 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 288 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 290 | */ | 289 | */ |
| 291 | - virtual void set_merge_read(bool v, int max_buffer, IMergeReadHandler* handler); | 290 | + virtual void set_merge_read(bool v, IMergeReadHandler* handler); |
| 292 | #endif | 291 | #endif |
| 293 | public: | 292 | public: |
| 294 | /** | 293 | /** |
-
请 注册 或 登录 后发表评论