正在显示
6 个修改的文件
包含
20 行增加
和
83 行删除
| @@ -736,7 +736,7 @@ The publish benchmark by [st-load](https://github.com/winlinvip/st-load): | @@ -736,7 +736,7 @@ The publish benchmark by [st-load](https://github.com/winlinvip/st-load): | ||
| 736 | * 2014-12-03, SRS 2.0.48, 1.4k(1400) publishers, 95%CPU, 140MB. [commit](https://github.com/winlinvip/simple-rtmp-server/commit/f35ec2155b1408d528a9f37da7904c9625186bcf) | 736 | * 2014-12-03, SRS 2.0.48, 1.4k(1400) publishers, 95%CPU, 140MB. [commit](https://github.com/winlinvip/simple-rtmp-server/commit/f35ec2155b1408d528a9f37da7904c9625186bcf) |
| 737 | * 2014-12-04, SRS 2.0.49, 1.4k(1400) publishers, 68%CPU, 144MB. | 737 | * 2014-12-04, SRS 2.0.49, 1.4k(1400) publishers, 68%CPU, 144MB. |
| 738 | * 2014-12-04, SRS 2.0.49, 2.5k(2500) publishers, 95%CPU, 404MB. [commit](https://github.com/winlinvip/simple-rtmp-server/commit/29324fab469e0f7cef9ad04ffdbce832ac7dd9ff) | 738 | * 2014-12-04, SRS 2.0.49, 2.5k(2500) publishers, 95%CPU, 404MB. [commit](https://github.com/winlinvip/simple-rtmp-server/commit/29324fab469e0f7cef9ad04ffdbce832ac7dd9ff) |
| 739 | -* 2014-12-04, SRS 2.0.51, 2.5k(2500) publishers, 92%CPU, 259MB. [commit](https://github.com/winlinvip/simple-rtmp-server/commit/f57801eb46c16755b173984b915a4166922df6a6) | 739 | +* 2014-12-04, SRS 2.0.51, 2.5k(2500) publishers, 91%CPU, 259MB. [commit](https://github.com/winlinvip/simple-rtmp-server/commit/f57801eb46c16755b173984b915a4166922df6a6) |
| 740 | 740 | ||
| 741 | ## Architecture | 741 | ## Architecture |
| 742 | 742 |
| @@ -30,23 +30,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -30,23 +30,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 30 | #include <srs_kernel_utility.hpp> | 30 | #include <srs_kernel_utility.hpp> |
| 31 | #include <srs_core_performance.hpp> | 31 | #include <srs_core_performance.hpp> |
| 32 | 32 | ||
| 33 | -// when we read from socket less than this value, | ||
| 34 | -// sleep a while to merge read. | ||
| 35 | -// @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | ||
| 36 | -// use the bitrate in kbps to calc the max sleep time. | ||
| 37 | -#define SRS_MR_MAX_BITRATE_KBPS 10000 | ||
| 38 | -#define SRS_MR_AVERAGE_BITRATE_KBPS 1000 | ||
| 39 | -#define SRS_MR_MIN_BITRATE_KBPS 32 | ||
| 40 | -// the max sleep time in ms | ||
| 41 | -#define SRS_MR_MAX_SLEEP_MS 2500 | ||
| 42 | -// the max small bytes to group | ||
| 43 | -#define SRS_MR_SMALL_BYTES 4096 | ||
| 44 | -// the percent of buffer to set as small bytes | ||
| 45 | -#define SRS_MR_SMALL_PERCENT 100 | ||
| 46 | -// set the socket buffer to specified bytes. | ||
| 47 | -// the underlayer api will set to SRS_MR_SOCKET_BUFFER bytes. | ||
| 48 | -#define SRS_MR_SOCKET_BUFFER SOCKET_READ_SIZE | ||
| 49 | - | ||
| 50 | ISrsMessageHandler::ISrsMessageHandler() | 33 | ISrsMessageHandler::ISrsMessageHandler() |
| 51 | { | 34 | { |
| 52 | } | 35 | } |
| @@ -253,8 +236,6 @@ SrsPublishRecvThread::SrsPublishRecvThread( | @@ -253,8 +236,6 @@ SrsPublishRecvThread::SrsPublishRecvThread( | ||
| 253 | error = st_cond_new(); | 236 | error = st_cond_new(); |
| 254 | 237 | ||
| 255 | mr_fd = fd; | 238 | mr_fd = fd; |
| 256 | - mr_small_bytes = 0; | ||
| 257 | - mr_sleep_ms = 0; | ||
| 258 | } | 239 | } |
| 259 | 240 | ||
| 260 | SrsPublishRecvThread::~SrsPublishRecvThread() | 241 | SrsPublishRecvThread::~SrsPublishRecvThread() |
| @@ -309,7 +290,8 @@ void SrsPublishRecvThread::on_thread_start() | @@ -309,7 +290,8 @@ void SrsPublishRecvThread::on_thread_start() | ||
| 309 | } | 290 | } |
| 310 | getsockopt(mr_fd, SOL_SOCKET, SO_RCVBUF, &nb_rbuf, &sock_buf_size); | 291 | getsockopt(mr_fd, SOL_SOCKET, SO_RCVBUF, &nb_rbuf, &sock_buf_size); |
| 311 | 292 | ||
| 312 | - srs_trace("set socket buffer to %d, actual %d KB", SRS_MR_SOCKET_BUFFER / 1024, nb_rbuf / 1024); | 293 | + srs_trace("merged read sockbuf=%d, actual=%d, sleep %d when nread<=%d", |
| 294 | + SRS_MR_SOCKET_BUFFER, nb_rbuf, SRS_MR_MAX_SLEEP_MS, SRS_MR_SMALL_BYTES); | ||
| 313 | 295 | ||
| 314 | // enable the merge read | 296 | // enable the merge read |
| 315 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 297 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| @@ -367,7 +349,7 @@ void SrsPublishRecvThread::on_recv_error(int ret) | @@ -367,7 +349,7 @@ void SrsPublishRecvThread::on_recv_error(int ret) | ||
| 367 | #ifdef SRS_PERF_MERGED_READ | 349 | #ifdef SRS_PERF_MERGED_READ |
| 368 | void SrsPublishRecvThread::on_read(ssize_t nread) | 350 | void SrsPublishRecvThread::on_read(ssize_t nread) |
| 369 | { | 351 | { |
| 370 | - if (nread < 0 || mr_sleep_ms <= 0) { | 352 | + if (nread < 0 || SRS_MR_MAX_SLEEP_MS <= 0) { |
| 371 | return; | 353 | return; |
| 372 | } | 354 | } |
| 373 | 355 | ||
| @@ -377,34 +359,8 @@ void SrsPublishRecvThread::on_read(ssize_t nread) | @@ -377,34 +359,8 @@ void SrsPublishRecvThread::on_read(ssize_t nread) | ||
| 377 | * that is, we merge some data to read together. | 359 | * that is, we merge some data to read together. |
| 378 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 360 | * @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 379 | */ | 361 | */ |
| 380 | - if (nread < mr_small_bytes) { | ||
| 381 | - st_usleep(mr_sleep_ms * 1000); | 362 | + if (nread < SRS_MR_SMALL_BYTES) { |
| 363 | + st_usleep(SRS_MR_MAX_SLEEP_MS * 1000); | ||
| 382 | } | 364 | } |
| 383 | } | 365 | } |
| 384 | - | ||
| 385 | -void SrsPublishRecvThread::on_buffer_change(int nb_buffer) | ||
| 386 | -{ | ||
| 387 | - srs_assert(nb_buffer > 0); | ||
| 388 | - | ||
| 389 | - // set percent. | ||
| 390 | - mr_small_bytes = (int)(nb_buffer / SRS_MR_SMALL_PERCENT); | ||
| 391 | - // select the smaller | ||
| 392 | - mr_small_bytes = srs_max(mr_small_bytes, SRS_MR_SMALL_BYTES); | ||
| 393 | - | ||
| 394 | - // the recv sleep is [buffer / max_kbps, buffer / min_kbps] | ||
| 395 | - // for example, buffer is 256KB, max kbps is 10Mbps, min kbps is 10Kbps, | ||
| 396 | - // the buffer is 256KB*8=2048Kb, which can provides sleep time in | ||
| 397 | - // min: 2038Kb/10Mbps=2038Kb/10Kbpms=203.8ms | ||
| 398 | - // max: 2038Kb/10Kbps=203.8s | ||
| 399 | - // sleep = Xb * 8 / (N * 1000 b / 1000 ms) = (X * 8 / N) ms | ||
| 400 | - // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | ||
| 401 | - int min_sleep = (int)(nb_buffer * 8.0 / SRS_MR_MAX_BITRATE_KBPS); | ||
| 402 | - int average_sleep = (int)(nb_buffer * 8.0 / SRS_MR_AVERAGE_BITRATE_KBPS); | ||
| 403 | - int max_sleep = (int)(nb_buffer * 8.0 / SRS_MR_MIN_BITRATE_KBPS); | ||
| 404 | - // 80% min, 16% average, 4% max. | ||
| 405 | - mr_sleep_ms = (int)(min_sleep * 0.8 + average_sleep * 0.16 + max_sleep * 0.04); | ||
| 406 | - mr_sleep_ms = srs_min(mr_sleep_ms, SRS_MR_MAX_SLEEP_MS); | ||
| 407 | - | ||
| 408 | - srs_trace("merged read, buffer=%d, small=%d, sleep=%d", nb_buffer, mr_small_bytes, mr_sleep_ms); | ||
| 409 | -} | ||
| 410 | #endif | 366 | #endif |
| @@ -147,8 +147,6 @@ private: | @@ -147,8 +147,6 @@ private: | ||
| 147 | // for mr(merged read), | 147 | // for mr(merged read), |
| 148 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | 148 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/241 |
| 149 | int mr_fd; | 149 | int mr_fd; |
| 150 | - int mr_small_bytes; | ||
| 151 | - int mr_sleep_ms; | ||
| 152 | // the recv thread error code. | 150 | // the recv thread error code. |
| 153 | int recv_error_code; | 151 | int recv_error_code; |
| 154 | SrsRtmpConn* _conn; | 152 | SrsRtmpConn* _conn; |
| @@ -184,7 +182,6 @@ public: | @@ -184,7 +182,6 @@ public: | ||
| 184 | public: | 182 | public: |
| 185 | #ifdef SRS_PERF_MERGED_READ | 183 | #ifdef SRS_PERF_MERGED_READ |
| 186 | virtual void on_read(ssize_t nread); | 184 | virtual void on_read(ssize_t nread); |
| 187 | - virtual void on_buffer_change(int nb_buffer); | ||
| 188 | #endif | 185 | #endif |
| 189 | }; | 186 | }; |
| 190 | 187 |
| @@ -64,8 +64,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -64,8 +64,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 64 | * buffer=65536B, small=4096B, sleep=780ms | 64 | * buffer=65536B, small=4096B, sleep=780ms |
| 65 | * that is, when got nread bytes smaller than 4KB, sleep(780ms). | 65 | * that is, when got nread bytes smaller than 4KB, sleep(780ms). |
| 66 | */ | 66 | */ |
| 67 | -#undef SRS_PERF_MERGED_READ | ||
| 68 | -#define SRS_PERF_MERGED_READ | 67 | +#if 1 |
| 68 | + // to enable merged read. | ||
| 69 | + #define SRS_PERF_MERGED_READ | ||
| 70 | + // the max sleep time in ms | ||
| 71 | + #define SRS_MR_MAX_SLEEP_MS 1000 | ||
| 72 | + // the max small bytes to group | ||
| 73 | + #define SRS_MR_SMALL_BYTES 4096 | ||
| 74 | + // the underlayer api will set to SRS_MR_SOCKET_BUFFER bytes. | ||
| 75 | + // 4KB=4096, 8KB=8192, 16KB=16384, 32KB=32768, 64KB=65536 | ||
| 76 | + #define SRS_MR_SOCKET_BUFFER 65536 | ||
| 77 | +#endif | ||
| 69 | 78 | ||
| 70 | /** | 79 | /** |
| 71 | * the send cache time in ms. | 80 | * the send cache time in ms. |
| @@ -93,7 +93,7 @@ SrsFastBuffer::SrsFastBuffer() | @@ -93,7 +93,7 @@ SrsFastBuffer::SrsFastBuffer() | ||
| 93 | p = end = buffer = NULL; | 93 | p = end = buffer = NULL; |
| 94 | nb_buffer = 0; | 94 | nb_buffer = 0; |
| 95 | 95 | ||
| 96 | - reset_buffer(SOCKET_READ_SIZE); | 96 | + reset_buffer(SRS_MR_SOCKET_BUFFER); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | SrsFastBuffer::~SrsFastBuffer() | 99 | SrsFastBuffer::~SrsFastBuffer() |
| @@ -192,15 +192,11 @@ void SrsFastBuffer::set_merge_read(bool v, int max_buffer, IMergeReadHandler* ha | @@ -192,15 +192,11 @@ void SrsFastBuffer::set_merge_read(bool v, int max_buffer, IMergeReadHandler* ha | ||
| 192 | _handler = handler; | 192 | _handler = handler; |
| 193 | 193 | ||
| 194 | // limit the max buffer. | 194 | // limit the max buffer. |
| 195 | - int buffer_size = srs_min(max_buffer, SOCKET_MAX_BUF); | 195 | + int buffer_size = srs_min(max_buffer, SRS_MR_SOCKET_BUFFER); |
| 196 | 196 | ||
| 197 | if (v && buffer_size != nb_buffer) { | 197 | if (v && buffer_size != nb_buffer) { |
| 198 | reset_buffer(buffer_size); | 198 | reset_buffer(buffer_size); |
| 199 | } | 199 | } |
| 200 | - | ||
| 201 | - if (_handler) { | ||
| 202 | - _handler->on_buffer_change(nb_buffer); | ||
| 203 | - } | ||
| 204 | } | 200 | } |
| 205 | #endif | 201 | #endif |
| 206 | 202 | ||
| @@ -211,17 +207,11 @@ void SrsFastBuffer::on_chunk_size(int32_t chunk_size) | @@ -211,17 +207,11 @@ void SrsFastBuffer::on_chunk_size(int32_t chunk_size) | ||
| 211 | } | 207 | } |
| 212 | 208 | ||
| 213 | // limit the max buffer. | 209 | // limit the max buffer. |
| 214 | - int buffer_size = srs_min(chunk_size, SOCKET_MAX_BUF); | 210 | + int buffer_size = srs_min(chunk_size, SRS_MR_SOCKET_BUFFER); |
| 215 | 211 | ||
| 216 | if (buffer_size != nb_buffer) { | 212 | if (buffer_size != nb_buffer) { |
| 217 | reset_buffer(buffer_size); | 213 | reset_buffer(buffer_size); |
| 218 | } | 214 | } |
| 219 | - | ||
| 220 | -#ifdef SRS_PERF_MERGED_READ | ||
| 221 | - if (_handler) { | ||
| 222 | - _handler->on_buffer_change(nb_buffer); | ||
| 223 | - } | ||
| 224 | -#endif | ||
| 225 | } | 215 | } |
| 226 | 216 | ||
| 227 | int SrsFastBuffer::buffer_size() | 217 | int SrsFastBuffer::buffer_size() |
| @@ -35,16 +35,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -35,16 +35,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 35 | #include <srs_protocol_io.hpp> | 35 | #include <srs_protocol_io.hpp> |
| 36 | #include <srs_core_performance.hpp> | 36 | #include <srs_core_performance.hpp> |
| 37 | 37 | ||
| 38 | -// 4KB=4096 | ||
| 39 | -// 8KB=8192 | ||
| 40 | -// 16KB=16384 | ||
| 41 | -// 32KB=32768 | ||
| 42 | -// 64KB=65536 | ||
| 43 | -// @see https://github.com/winlinvip/simple-rtmp-server/issues/241 | ||
| 44 | -#define SOCKET_READ_SIZE 65536 | ||
| 45 | -// the max buffer for user space socket buffer. | ||
| 46 | -#define SOCKET_MAX_BUF SOCKET_READ_SIZE | ||
| 47 | - | ||
| 48 | /** | 38 | /** |
| 49 | * the simple buffer use vector to append bytes, | 39 | * the simple buffer use vector to append bytes, |
| 50 | * it's for hls and http, and need to be refined in future. | 40 | * it's for hls and http, and need to be refined in future. |
| @@ -101,11 +91,6 @@ public: | @@ -101,11 +91,6 @@ public: | ||
| 101 | * @remark, it only for server-side, client srs-librtmp just ignore. | 91 | * @remark, it only for server-side, client srs-librtmp just ignore. |
| 102 | */ | 92 | */ |
| 103 | virtual void on_read(ssize_t nread) = 0; | 93 | virtual void on_read(ssize_t nread) = 0; |
| 104 | - /** | ||
| 105 | - * when buffer size changed. | ||
| 106 | - * @param nb_buffer the new buffer size. | ||
| 107 | - */ | ||
| 108 | - virtual void on_buffer_change(int nb_buffer) = 0; | ||
| 109 | }; | 94 | }; |
| 110 | #endif | 95 | #endif |
| 111 | 96 |
-
请 注册 或 登录 后发表评论